我已经搭建了一个完整的堆栈-- Mongo,Express,with,Node应用程序--使用yeoman和角满堆栈生成器
它创建了一个server/app.js文件,它执行一个routes.js来处理由快递服务器提供的资源。
routes.js的肉看起来如下:
// Insert routes below
app.use('/api/things', require('./api/thing'));
app.use('/api/users', require('./api/user'));
app.use('/auth', require('./auth'));
// All undefined asset or api routes should return a 404
app.route('/:url(api|auth|components|app|bower_components|assets)/*')
.get(errors[404]);
// All other routes should redirect to the index.html
app.route('/*')
.get(function(req, res) {
res.sendfile(app.get('appPath') + '/index.html');
});我的问题是,除index.html之外的任何文件如何被送达浏览器。我已经测试过了,例如,文件"http://localhost:9000/assets/images/yeoman.png“确实会返回到浏览器。但是怎么做呢?根据我在routes.js中看到的内容,对png的请求应该返回index.html的文本。
我对此感到有点困惑,我很想得到一个解释。
谢谢!
发布于 2015-06-16 17:45:41
如果您进入config/press.js,您将看到如下所示:
app.use(express.static(path.join(config.root, 'public')));这应该是不言自明的。
使用路由的UPD.可以为特定的文件覆盖这种行为(如果您真的需要的话)。
https://stackoverflow.com/questions/30874449
复制相似问题