1
0
mirror of https://github.com/lus/pasty.git synced 2023-08-10 21:13:09 +03:00

Fix buggy frontend routing

This commit is contained in:
Lukas SP
2020-08-24 18:32:14 +02:00
parent 6b0d0007e2
commit f5357a2c9d
9 changed files with 8 additions and 3 deletions

View File

@ -29,7 +29,7 @@ func Serve() error {
frontend := frontendHandler()
router.GET("/{path:*}", func(ctx *fasthttp.RequestCtx) {
path := string(ctx.Path())
if !strings.HasPrefix(path, "/api") {
if !strings.HasPrefix(path, "/api") && (strings.Count(path, "/") == 1 || strings.HasPrefix(path, "/assets")) {
frontend(ctx)
return
}
@ -88,6 +88,11 @@ func frontendHandler() fasthttp.RequestHandler {
CacheDuration: 0,
}
fs.PathNotFound = func(ctx *fasthttp.RequestCtx) {
if strings.HasPrefix(string(ctx.Path()), "/assets") {
ctx.SetStatusCode(fasthttp.StatusNotFound)
ctx.SetBodyString("not found")
return
}
ctx.SendFile(filepath.Join(fs.Root, "index.html"))
}
return fs.NewRequestHandler()