Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Express SPA history API express.static fallback

Mostly taken from:, without all the repo/package fluff.

let staticPath = '/path/to/dist'


app.use('/', ((...args) => (req, res, next) => {
  if ((req.method === 'GET' || req.method === 'HEAD') && req.accepts('html')) {
    (res.sendFile || res.sendfile).call(res, ...args, err => err && next())
  } else next()
})('index.html', {
  root: staticPath
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.