【发布时间】:2015-06-17 01:45:41
【问题描述】:
我已经使用 yeoman 和 Angular Fullstack 生成器搭建了一个完整堆栈的 Mongo、Express、Angular、Node 应用程序
它创建了一个 server/app.js 文件,该文件执行一个 routes.js 来处理由 express 服务器提供的资源。
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
的文本我对此有点困惑,非常感谢您的解释。
谢谢!
【问题讨论】:
标签: javascript node.js express