How can I enable html5mode

157 views
Skip to first unread message

Alexander Dudko

unread,
Mar 29, 2015, 7:01:08 PM3/29/15
to loopb...@googlegroups.com
I use angularJS + loopback and I want to redirect all requests to the index.html file like this but I do not understand how to do this with the loopback

https://github.com/angular-ui/ui-router/wiki/Frequently-Asked-Questions#how-to-configure-your-server-to-work-with-html5mode

Bryan Clark

unread,
Mar 31, 2015, 11:25:57 PM3/31/15
to loopb...@googlegroups.com
In your server.js file you can use loopback like you would express, so the express example from that page works.

https://gist.github.com/clarkbw/93bcbbc13bad80eb472a

The following will work, but if you're using middleware.json you might want to set this up differently so you can still get your other static files served.  See the Defining Middleware docs if that is the case.

var path = require('path');
// https://github.com/angular-ui/ui-router/wiki/Frequently-Asked-Questions#how-to-configure-your-server-to-work-with-html5mode

app
.all('/*', function(req, res, next) {
 
// Just send the index.html for other files to support HTML5Mode
 res
.sendFile('index.html', { root: path.resolve(__dirname, '..', 'client') });
});


Reply all
Reply to author
Forward
0 new messages