mirror of
https://github.com/PluralKit/PluralKit.git
synced 2026-02-04 04:56:49 +00:00
feat(api): init rust rewrite
This commit is contained in:
parent
5da3c84bce
commit
5440386969
24 changed files with 2443 additions and 586 deletions
|
|
@ -3,9 +3,11 @@ package main
|
|||
import (
|
||||
"embed"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"html"
|
||||
"io"
|
||||
_fs "io/fs"
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
|
|
@ -78,12 +80,21 @@ func notFoundHandler(rw http.ResponseWriter, r *http.Request) {
|
|||
data = []byte(strings.Replace(string(data), `<!-- extra data -->`, defaultEmbed+versionJS, 1))
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
if errors.Is(err, _fs.ErrNotExist) {
|
||||
rw.WriteHeader(http.StatusNotFound)
|
||||
} else if err != nil {
|
||||
rw.WriteHeader(http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
} else {
|
||||
// cache built+hashed dashboard js/css files forever
|
||||
is_dash_static_asset := strings.HasPrefix(r.URL.Path, "/assets/") &&
|
||||
(strings.HasSuffix(r.URL.Path, ".js") || strings.HasSuffix(r.URL.Path, ".css") || strings.HasSuffix(r.URL.Path, ".map"))
|
||||
|
||||
rw.Write(data)
|
||||
if is_dash_static_asset {
|
||||
rw.Header().Add("Cache-Control", "max-age=31536000, s-maxage=31536000, immutable")
|
||||
}
|
||||
|
||||
rw.Write(data)
|
||||
}
|
||||
}
|
||||
|
||||
// explanation for createEmbed:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue