用restify提供静态文件(node.js) [英] serving static files with restify (node.js)

查看:218
本文介绍了用restify提供静态文件(node.js)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下代码:

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"
}

我尝试了几种变体,但似乎都没有。

I tried with several variations, but none of them seemed to work.

我确定它应该是非常明显我缺少的东西

I'm sure it should be something pretty obvious I'm missing

推荐答案

restify 将使用目录选项作为整个路径路径的前缀。在您的情况下,它将查找 ./ public / docs / public / index.html

restify will use the directory option as a prefix for the entire route path. In your case, it will look for ./public/docs/public/index.html.

这篇关于用restify提供静态文件(node.js)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆