Fixed gzip in /static/
The me endpoint is no longer served for guests.
This commit is contained in:
parent
3fc2d6a867
commit
4c86c0a042
|
@ -125,8 +125,8 @@ function fetchPhrases() {
|
||||||
(() => {
|
(() => {
|
||||||
runInitHook("pre_iife");
|
runInitHook("pre_iife");
|
||||||
let loggedIn = document.head.querySelector("[property='x-loggedin']").content;
|
let loggedIn = document.head.querySelector("[property='x-loggedin']").content;
|
||||||
|
if(loggedIn) {
|
||||||
fetch("/api/me/")
|
fetch("/api/me/")
|
||||||
.then((resp) => resp.json())
|
.then((resp) => resp.json())
|
||||||
.then((data) => {
|
.then((data) => {
|
||||||
console.log("loaded me endpoint data");
|
console.log("loaded me endpoint data");
|
||||||
|
@ -135,12 +135,14 @@ function fetchPhrases() {
|
||||||
runInitHook("pre_init");
|
runInitHook("pre_init");
|
||||||
});
|
});
|
||||||
|
|
||||||
if(loggedIn) {
|
|
||||||
let toLoad = 1;
|
let toLoad = 1;
|
||||||
loadScript("template_topics_topic.js", () => {
|
loadScript("template_topics_topic.js", () => {
|
||||||
console.log("Loaded template_topics_topic.js");
|
console.log("Loaded template_topics_topic.js");
|
||||||
toLoad--;
|
toLoad--;
|
||||||
if(toLoad===0) fetchPhrases();
|
if(toLoad===0) fetchPhrases();
|
||||||
});
|
});
|
||||||
|
} else {
|
||||||
|
me = {User:{ID:0,Session:""},Site:{"MaxRequestSize":0}};
|
||||||
|
runInitHook("pre_init");
|
||||||
}
|
}
|
||||||
})();
|
})();
|
|
@ -27,7 +27,7 @@ func StaticFile(w http.ResponseWriter, r *http.Request) {
|
||||||
h := w.Header()
|
h := w.Header()
|
||||||
|
|
||||||
// Surely, there's a more efficient way of doing this?
|
// Surely, there's a more efficient way of doing this?
|
||||||
t, err := time.Parse(http.TimeFormat, h.Get("If-Modified-Since"))
|
t, err := time.Parse(http.TimeFormat, r.Header.Get("If-Modified-Since"))
|
||||||
if err == nil && file.Info.ModTime().Before(t.Add(1*time.Second)) {
|
if err == nil && file.Info.ModTime().Before(t.Add(1*time.Second)) {
|
||||||
w.WriteHeader(http.StatusNotModified)
|
w.WriteHeader(http.StatusNotModified)
|
||||||
return
|
return
|
||||||
|
@ -36,7 +36,8 @@ func StaticFile(w http.ResponseWriter, r *http.Request) {
|
||||||
h.Set("Content-Type", file.Mimetype)
|
h.Set("Content-Type", file.Mimetype)
|
||||||
h.Set("Cache-Control", cacheControlMaxAge) //Cache-Control: max-age=31536000
|
h.Set("Cache-Control", cacheControlMaxAge) //Cache-Control: max-age=31536000
|
||||||
h.Set("Vary", "Accept-Encoding")
|
h.Set("Vary", "Accept-Encoding")
|
||||||
if strings.Contains(h.Get("Accept-Encoding"), "gzip") {
|
|
||||||
|
if strings.Contains(r.Header.Get("Accept-Encoding"), "gzip") {
|
||||||
h.Set("Content-Encoding", "gzip")
|
h.Set("Content-Encoding", "gzip")
|
||||||
h.Set("Content-Length", strconv.FormatInt(file.GzipLength, 10))
|
h.Set("Content-Length", strconv.FormatInt(file.GzipLength, 10))
|
||||||
io.Copy(w, bytes.NewReader(file.GzipData)) // Use w.Write instead?
|
io.Copy(w, bytes.NewReader(file.GzipData)) // Use w.Write instead?
|
||||||
|
|
Loading…
Reference in New Issue