我的Angular / Node / Express应用程序在生产模式下提供index.html而不是静态资产 - 为什么?

时间:2014-01-21 13:30:18

标签: node.js angularjs express routing

我有一个基于 generator-angular-fullstack 构建的Angular / Node / Express webapp。

在开发模式下,该应用程序运行正常。但是在生产模式下,只要请求静态资产(图像,CSS),它就会服务index.html,我无法弄清楚原因 - 我想我的ExpressJS路由有问题。

lib / express.js:设置静态资产的路径

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

0 个答案:

没有答案