Skip to content

Commit

Permalink
add redirect for static 404
Browse files Browse the repository at this point in the history
  • Loading branch information
zhyale committed Sep 29, 2021
1 parent de1a548 commit 61786f2
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 11 deletions.
20 changes: 13 additions & 7 deletions gateway/gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ func ReverseHandlerFunc(w http.ResponseWriter, r *http.Request) {
}
captchaHitInfo.Store(hitInfo.ClientID, hitInfo)
captchaURL := CaptchaEntrance + "?id=" + hitInfo.ClientID
http.Redirect(w, r, captchaURL, http.StatusTemporaryRedirect)
http.Redirect(w, r, captchaURL, http.StatusFound)
return
}
}
Expand Down Expand Up @@ -346,6 +346,12 @@ func ReverseHandlerFunc(w http.ResponseWriter, r *http.Request) {
http.ServeFile(w, r, targetFile)
return
}
targetFile := dest.BackendRoute + strings.Replace(r.URL.Path, dest.RequestRoute, "", 1)
if _, err := os.Stat(targetFile); os.IsNotExist(err) {
// targetFile not exists
http.Redirect(w, r, dest.RequestRoute, http.StatusFound)
return
}
http.StripPrefix(dest.RequestRoute, staticHandler).ServeHTTP(w, r)
return
} else if dest.RouteType == models.FastCGIRoute {
Expand Down Expand Up @@ -494,28 +500,28 @@ func ReverseHandlerFunc(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Encoding", "br")
brWriter := brotli.NewWriter(w)
defer brWriter.Close()
zipResponseWriter := models.ZipResponseWriter {
Writer: brWriter,
zipResponseWriter := models.ZipResponseWriter{
Writer: brWriter,
ResponseWriter: w,
}
http.ServeFile(zipResponseWriter, r, targetFile)
} else if strings.Contains(acceptEncoding, "gzip") {
w.Header().Set("Content-Encoding", "gzip")
gzWriter := gzip.NewWriter(w)
defer gzWriter.Close()
zipResponseWriter := models.ZipResponseWriter {
Writer: gzWriter,
zipResponseWriter := models.ZipResponseWriter{
Writer: gzWriter,
ResponseWriter: w,
}
http.ServeFile(zipResponseWriter, r, targetFile)
} else {
http.ServeFile(w, r, targetFile)
}
}
return
}
}
// Has Range Header, or resource Not Found, Continue
// For static files, disable compression between gateway and backend
// For static files, disable compression between gateway and backend
r.Header.Set("Accept-Encoding", "")
}
}
Expand Down
2 changes: 1 addition & 1 deletion release_batch.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ printf "Creating installation package\n"
printf "Checklist:\n"
printf "* Angular Admin Version Check. \n"
printf "* Janusec Version Check. \n"
version="1.2.5"
version="1.2.6"
printf "Version: ${version} \n"

read -r -p "Are You Sure? [Y/n] " option
Expand Down
2 changes: 1 addition & 1 deletion static/janusec-admin/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@
<link rel="stylesheet" href="/janusec-admin/styles.50eb2ccb7b9839eeeaea.css"></head>
<body>
<app-root></app-root>
<script src="/janusec-admin/runtime-es2015.871528d607deca2f7955.js" type="module"></script><script src="/janusec-admin/runtime-es5.871528d607deca2f7955.js" nomodule defer></script><script src="/janusec-admin/polyfills-es5.6bea2bc8703c1ccf8076.js" nomodule defer></script><script src="/janusec-admin/polyfills-es2015.18873f30415c143a1eb4.js" type="module"></script><script src="/janusec-admin/main-es2015.788ee1c1a4f66bf0f59a.js" type="module"></script><script src="/janusec-admin/main-es5.788ee1c1a4f66bf0f59a.js" nomodule defer></script></body>
<script src="/janusec-admin/runtime-es2015.871528d607deca2f7955.js" type="module"></script><script src="/janusec-admin/runtime-es5.871528d607deca2f7955.js" nomodule defer></script><script src="/janusec-admin/polyfills-es5.6bea2bc8703c1ccf8076.js" nomodule defer></script><script src="/janusec-admin/polyfills-es2015.18873f30415c143a1eb4.js" type="module"></script><script src="/janusec-admin/main-es2015.a286f0ec7364b64750f4.js" type="module"></script><script src="/janusec-admin/main-es5.a286f0ec7364b64750f4.js" nomodule defer></script></body>
</html>

Large diffs are not rendered by default.

Large diffs are not rendered by default.

0 comments on commit 61786f2

Please sign in to comment.