Skip to content

Commit

Permalink
Merge pull request #40 from gstvribs/master
Browse files Browse the repository at this point in the history
Fix single page application routing to index html - via directly or url
  • Loading branch information
daquinoaldo committed Mar 2, 2020
2 parents fb3af87 + 47eaf3a commit 83ba98a
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,13 @@ const createServer = (domain = "localhost") => {
app.use(express.static(staticPath))
// redirect 404 to 404.html or to index.html
app.use((req, res) => {
if (!staticPath.startsWith("/"))
staticPath = process.cwd() + "/" + staticPath
const p404 = staticPath + "/404.html"
const index = staticPath + "/index.html"
// istanbul ignore else: not interesting
if (fs.existsSync(p404))
res.status(404).sendFile(p404)
res.status(404).sendFile(path.resolve(p404))
else if (fs.existsSync(index))
res.status(404).sendFile(index)
res.status(404).sendFile(path.resolve(index))
else res.status(404).send(req.path + " not found.")
})
console.info("Serving static path: " + staticPath)
Expand Down

0 comments on commit 83ba98a

Please sign in to comment.