我有以下代码:
app.js
[...]
server.get(/\/docs\/public\/?.*/, restify.serveStatic({
directory: './public'
}));
server.listen(1337, function() {
console.log('%s listening at %s', server.name, server.url);
});
我有以下文件结构
app.js
public/
index.html
所以我尝试浏览:
http://localhost:1337/docs/public/index.html
我明白了
{
code: "ResourceNotFound",
message: "/docs/public/index.html"
}
我尝试了几种变体,但似乎都不起作用。
我确定这应该是很明显的我想念的东西
最佳答案
restify
将使用directory
选项作为整个路由路径 的前缀。在您的情况下,它将查找 ./public/docs/public/index.html
.
关于node.js - 使用 restify (node.js) 提供静态文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15463841/