我正在学习使用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