node.js - 使用 restify (node.js) 提供静态文件

标签 node.js http restify

我有以下代码:

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/

相关文章:

javascript - JS 字符串的行为不符合预期

Gitlab 6.2 在推送到源时要求用户名和密码身份验证

node.js - 强制使用网址中的查询参数格式

node.js - req.url 未显示完整 URL

node.js - nodejs/restify - 图像代理服务器

javascript - JSON.parse 无法使用 Twitter 流 api 中的 json

node.js - 无法使用 Angular 2 从 Node.js 服务器获取数据

javascript - 将 Float32Array 转换为缓冲区

ios - 这是我的 HTTP POST 请求,但我成功获得了连接。它显示响应为空。如何纠正这个?

node.js - 在 application/octet-stream 中使用 restify 设置内容类型 header