在restify中提供带或不带扩展名的静态文件

时间:2016-06-02 21:37:03

标签: node.js restify

我需要同时提供http://localhost/users/listhttp://localhost/users/list.html

server.get(/.*/, restify.serveStatic({
    directory: './public',
}));

此代码仅在您指定.html扩展名时有效。

1 个答案:

答案 0 :(得分:0)

我使用serve-static作为expressjshttp的中间件,并且有效。

var restify = require('restify');
var serveStatic = require('serve-static');

server = restify.createServer(options);

server.use(restify.acceptParser(server.acceptable));
server.use(restify.queryParser());
server.use(restify.bodyParser());
server.use(serveStatic('./public', { extensions: ['html'] }));

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

server.listen(80, function () {
    console.log('Server is running...')
});