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()
|
frontend := frontendHandler()
|
||||||
router.GET("/{path:*}", func(ctx *fasthttp.RequestCtx) {
|
router.GET("/{path:*}", func(ctx *fasthttp.RequestCtx) {
|
||||||
path := string(ctx.Path())
|
path := string(ctx.Path())
|
||||||
if !strings.HasPrefix(path, "/api") {
|
if !strings.HasPrefix(path, "/api") && (strings.Count(path, "/") == 1 || strings.HasPrefix(path, "/assets")) {
|
||||||
frontend(ctx)
|
frontend(ctx)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -88,6 +88,11 @@ func frontendHandler() fasthttp.RequestHandler {
|
|||||||
CacheDuration: 0,
|
CacheDuration: 0,
|
||||||
}
|
}
|
||||||
fs.PathNotFound = func(ctx *fasthttp.RequestCtx) {
|
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"))
|
ctx.SendFile(filepath.Join(fs.Root, "index.html"))
|
||||||
}
|
}
|
||||||
return fs.NewRequestHandler()
|
return fs.NewRequestHandler()
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
<meta charset="UTF-8">
|
<meta charset="UTF-8">
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
<title>pasty</title>
|
<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">
|
<link rel="stylesheet" href="//cdn.jsdelivr.net/gh/highlightjs/cdn-release@10.1.2/build/styles/default.min.css">
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
@ -63,6 +63,6 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<script src="//cdn.jsdelivr.net/gh/highlightjs/cdn-release@10.1.2/build/highlight.min.js"></script>
|
<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>
|
</body>
|
||||||
</html>
|
</html>
|
Loading…
Reference in New Issue
Block a user