My Angular/Node/Express app serves index.html instead of static assets in production mode - why?

感情迁移 提交于 2020-01-14 05:51:10

问题


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');
    });
};

来源:https://stackoverflow.com/questions/21259599/my-angular-node-express-app-serves-index-html-instead-of-static-assets-in-produc

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!