Skip to content

Instantly share code, notes, and snippets.

@maxmckenzie
Created July 13, 2019 09:33
Show Gist options
  • Save maxmckenzie/947e25a7900ec4237f2917c5d0de5f4f to your computer and use it in GitHub Desktop.
Save maxmckenzie/947e25a7900ec4237f2917c5d0de5f4f to your computer and use it in GitHub Desktop.
vue express server with history fallback
var express = require('express')
var path = require('path')
const history = require('connect-history-api-fallback')
const app = express()
app.use(express.static(path.join(__dirname, 'static')))
app.use(express.static(path.join(__dirname, 'dist')))
app.use(history({
index: '/',
logger: console.log.bind(console),
disableDotRule: true,
verbose: true
}))
app.get('*', (req, res) => res.sendFile(path.join(__dirname, 'dist/index.html')))
const port = process.env.PORT || 8080
const server = app.listen(port, () => {
console.log('running on http://localhost:' + port)
})
module.exports = {
server,
app
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment