解析js默认根页面

时间:2014-04-26 18:11:53

标签: javascript node.js restify

我正在尝试使用node.js解析来编写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。 我还希望在根网址http://localhost:3000/上看到我的index.html页面,但现在我正在接收

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

1 个答案:

答案 0 :(得分:4)

尝试一下:

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