Created
July 13, 2019 09:33
-
-
Save maxmckenzie/947e25a7900ec4237f2917c5d0de5f4f to your computer and use it in GitHub Desktop.
vue express server with history fallback
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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