I\'m new to Express and I\'m trying to set up a SPA where every url is handled by index.html (Backbone).
I want every url to send down index.html, except /bundle.js
I managed to solve it this way:
const getExtension = fileName => (
fileName.substr(fileName.lastIndexOf('.') + 1)
)
app.get('*', ({ url }, res) => {
let filePath
if (['js', 'css', 'png', 'jpg'].includes(getExtension(url))) {
filePath = __dirname + '/public/' + url
} else {
filePath = __dirname + '/public/' + url + '/index.html'
}
res.sendFile(filePath)
});