From f5357a2c9d23bfe9f6f5725d259911148d1f61d7 Mon Sep 17 00:00:00 2001 From: Lukas SP Date: Mon, 24 Aug 2020 18:32:14 +0200 Subject: [PATCH] Fix buggy frontend routing --- internal/web/web.go | 7 ++++++- web/{ => assets}/css/style.css | 0 web/{ => assets}/css/style.css.map | 0 web/{ => assets}/css/style.scss | 0 web/{ => assets}/js/api.js | 0 web/{ => assets}/js/autoload.js | 0 web/{ => assets}/js/buttons.js | 0 web/{ => assets}/js/spinner.js | 0 web/index.html | 4 ++-- 9 files changed, 8 insertions(+), 3 deletions(-) rename web/{ => assets}/css/style.css (100%) rename web/{ => assets}/css/style.css.map (100%) rename web/{ => assets}/css/style.scss (100%) rename web/{ => assets}/js/api.js (100%) rename web/{ => assets}/js/autoload.js (100%) rename web/{ => assets}/js/buttons.js (100%) rename web/{ => assets}/js/spinner.js (100%) diff --git a/internal/web/web.go b/internal/web/web.go index 01e22ce..dd952a0 100644 --- a/internal/web/web.go +++ b/internal/web/web.go @@ -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() diff --git a/web/css/style.css b/web/assets/css/style.css similarity index 100% rename from web/css/style.css rename to web/assets/css/style.css diff --git a/web/css/style.css.map b/web/assets/css/style.css.map similarity index 100% rename from web/css/style.css.map rename to web/assets/css/style.css.map diff --git a/web/css/style.scss b/web/assets/css/style.scss similarity index 100% rename from web/css/style.scss rename to web/assets/css/style.scss diff --git a/web/js/api.js b/web/assets/js/api.js similarity index 100% rename from web/js/api.js rename to web/assets/js/api.js diff --git a/web/js/autoload.js b/web/assets/js/autoload.js similarity index 100% rename from web/js/autoload.js rename to web/assets/js/autoload.js diff --git a/web/js/buttons.js b/web/assets/js/buttons.js similarity index 100% rename from web/js/buttons.js rename to web/assets/js/buttons.js diff --git a/web/js/spinner.js b/web/assets/js/spinner.js similarity index 100% rename from web/js/spinner.js rename to web/assets/js/spinner.js diff --git a/web/index.html b/web/index.html index 20af6f6..ffcbed4 100644 --- a/web/index.html +++ b/web/index.html @@ -4,7 +4,7 @@ pasty - + @@ -63,6 +63,6 @@ - + \ No newline at end of file