是否可以将文件系统根目录和/或文档根目录设置为文件系统的某个子目录?
我想知道是否可以在node.js 中为文件系统根目录或文档根目录指定静态资源请求(如果有任何此类区别)。
我知道我可以通过连接从根开始的绝对路径来做到这一点,但我想知道是否可以在应用程序范围内完成。
我没有在文档中找到任何支持它的内容,但也许我忽略了它。
编辑: 我应该提到,我目前对使用第三方库不感兴趣。
I would like to know if it is possible to specify a subdirectory for the filesystem root or the document root for requests of static resources (if there's any such distinction) in node.js.
I know that I can do it by concatenating an absolute path from the root, but I'm wondering if it can be done on an application-wide level.
I haven't found anything in the documentation supports it, but perhaps I'm overlooking it.
EDIT: I should mention that I'm not interested in using a 3rd party library at this point.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
查看expressjs
http://expressjs.com/guide.html#configuration
具体来说
Express/connect 有此用例的“静态”中间件。还有其他较小的软件包仅用于静态文件服务,但是,express 很好并且维护得很好。
Check out expressjs
http://expressjs.com/guide.html#configuration
Specifically
Express/connect has a 'static' middleware for this use case. There are other smaller packages just for static file serving, however, express is nice and well maintained.
API 不允许您直接执行您要求的操作。您将需要使用字符串连接。
The API does not allow you to do what you're asking for directly. You will need to use string concat.
我已经用 Node.js 尝试了以下脚本并且运行良好。它以当前路径作为文档根来提供服务。
应用程序.js
参考资料在这里:
http://expressjs.com/starter/static-files.html
I've tried the following script with nodejs and works well. it takes the current path as document root to serve.
app.js
the reference is here:
http://expressjs.com/starter/static-files.html