gpt4 book ai didi

javascript - restify js默认根页面

转载 作者:搜寻专家 更新时间:2023-11-01 00:32:43 26 4
gpt4 key购买 nike

我正在尝试使用 node.js restify 编写 Restful 应用程序。这是我的应用程序代码:

var restify = require('restify');

var server = restify.createServer();

server.get(/.*/, restify.serveStatic({
directory: 'content',
default: 'index.html'
}));

server.listen(3000, function() {
console.log('%s listening at %s', server.name, server.url);
});

因此,我只能通过http://localhost:3000/index.html 访问index.html。我还希望在根 url http://localhost:3000/ 上看到我的 index.html 页面,但现在我正在那里接收

{"code":"ResourceNotFound","message":"/"}

最佳答案

试一试:

server.get(/\//, restify.serveStatic({
directory: './content',
default: 'index.html'
}));

关于javascript - restify js默认根页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23314755/

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