I need serve both http://localhost/users/list and http://localhost/users/list.html
server.get(/.*/, restify.serveStatic({
directory: './public',
}));
This code only works if you specify the .html extension.
I used serve-static which is middleware for expressjs and http and it worked.
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...')
});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.