Skip to content

Instantly share code, notes, and snippets.

@mbenedettini
Last active April 10, 2018 17:25
Show Gist options
  • Save mbenedettini/950ebe05cb278efe67a2ed7b53c3eefa to your computer and use it in GitHub Desktop.
Save mbenedettini/950ebe05cb278efe67a2ed7b53c3eefa to your computer and use it in GitHub Desktop.
loopback angular html5 mode
/*
I usually insert this snippet right at the beginning of server.js
*/
const path = require('path');
const staticRoot = path.resolve(__dirname, '..', 'client-dist');
app.all('/*', function(req, res, next) {
if (req.url.startsWith('/api')) {
return next();
}
if (req.url.startsWith('/agendash')) {
return next();
}
let asset =
req.url.match(/\/(assets\/.*)/) ||
req.url.match(/\/(.*\.(js|css|map|png|svg|jpg|xlsx))\??/);
if (asset) {
return res.sendFile(asset[1], {root: staticRoot });
}
// Just send the index.html for other files to support HTML5Mode
res.sendFile('index.html', { root: staticRoot });
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment