gpt4 book ai didi

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

转载 作者:IT老高 更新时间:2023-10-28 22:03:44 25 4
gpt4 key购买 nike

我有以下代码:

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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com