Skip to content

Commit 47eaf3a

Browse files
committed
Fix single page application routing to index html - via directly or url
1 parent fb3af87 commit 47eaf3a

File tree

1 file changed

+2
-4
lines changed

1 file changed

+2
-4
lines changed

index.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,15 +63,13 @@ const createServer = (domain = "localhost") => {
6363
app.use(express.static(staticPath))
6464
// redirect 404 to 404.html or to index.html
6565
app.use((req, res) => {
66-
if (!staticPath.startsWith("/"))
67-
staticPath = process.cwd() + "/" + staticPath
6866
const p404 = staticPath + "/404.html"
6967
const index = staticPath + "/index.html"
7068
// istanbul ignore else: not interesting
7169
if (fs.existsSync(p404))
72-
res.status(404).sendFile(p404)
70+
res.status(404).sendFile(path.resolve(p404))
7371
else if (fs.existsSync(index))
74-
res.status(404).sendFile(index)
72+
res.status(404).sendFile(path.resolve(index))
7573
else res.status(404).send(req.path + " not found.")
7674
})
7775
console.info("Serving static path: " + staticPath)

0 commit comments

Comments
 (0)