我正在學習使用Node.js.目前,我有一個文件夾結構如下所示:使用RESTIFY服務靜態文件
index.html
server.js
client
index.html
subs
index.html
page.html
res
css
style.css
img
profile.png
js
page.js
jquery.min.js
server.js是我的web服務器的代碼。我使用node server.js
從命令行運行。該文件的內容是:
var restify = require('restify');
var server = restify.createServer({
name: 'Test App',
version: '1.0.0'
});
server.use(restify.acceptParser(server.acceptable));
server.use(restify.queryParser());
server.use(restify.bodyParser());
server.get('/echo/:name', function (req, res, next) {
res.send(req.params);
return next();
});
server.listen(2000, function() {
console.log('%s running on %s', server.name, server.url);
});
如您所見,此服務器依賴於RESTIFY。我被告知我必須使用RESTIFY。但是,我無法弄清楚如何提供靜態文件。例如,如何在我的應用程序中爲* .html,* .css,* .png和* .js文件提供服務?
謝謝!
可能的重複:http://stackoverflow.com/questions/15463841/serving-static-files-with-restify-node-js?rq = 1 – vinaut