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

Serve static files with or without extension in restify

我需要同时服务 http://localhost/users/list and http://localhost/users/list.html

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

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

我用过 serve-static which is middleware for expressjs and http 并且有效。

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...')
});