I have an Angular/Node/Express webapp built on generator-angular-fullstack.
In development mode, the app works just fine. But in production mode, it serves index.html
whenever static assets (images, CSS) are requested, and I can't figure out why - I guess something is wrong with my ExpressJS routing.
lib/express.js: set path for static assets
// Mode: Production
app.configure('production', function(){
app.use(express.favicon(path.join(config.root, 'public', 'favicon.ico')));
app.use(express.static(path.join(config.root, 'public')));
app.set('views', config.root + '/views');
});
lib/routes.js:
module.exports = function(app) {
// Server API Routes
app.get('/api/awesomeThings', api.awesomeThings);
app.post('/api/users', users.create);
app.put('/api/users', users.changePassword);
app.get('/api/users/me', users.me);
app.get('/api/users/:id', users.show);
app.post('/api/session', session.login);
app.del('/api/session', session.logout);
// All other routes to use Angular routing in app/scripts/app.js
app.get('/partials/*', index.partials); // index.partials defined in controllers/index.js
app.get('/common/*', index.partials);
app.get('/ui-editor/*', index.partials);
app.get('/*', middleware.setUserCookie, function(req, res) {
res.render('index');
});
};