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:
parent
6b0d0007e2
commit
f5357a2c9d
@ -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()
|
||||
|
@ -4,7 +4,7 @@
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>pasty</title>
|
||||
<link rel="stylesheet" href="css/style.css">
|
||||
<link rel="stylesheet" href="assets/css/style.css">
|
||||
<link rel="stylesheet" href="//cdn.jsdelivr.net/gh/highlightjs/cdn-release@10.1.2/build/styles/default.min.css">
|
||||
</head>
|
||||
<body>
|
||||
@ -63,6 +63,6 @@
|
||||
</div>
|
||||
</div>
|
||||
<script src="//cdn.jsdelivr.net/gh/highlightjs/cdn-release@10.1.2/build/highlight.min.js"></script>
|
||||
<script src="js/autoload.js" type="module"></script>
|
||||
<script src="assets/js/autoload.js" type="module"></script>
|
||||
</body>
|
||||
</html>
|
Loading…
Reference in New Issue
Block a user