遇到express.static()方法, 但是有点不懂它到底是怎么用的.
思考到的一个问题是,访问一个网站的时候,例如www.test.com,他是怎么把url改成www.test.com/index.html的?
给一下我的认为的代码吧(一个大致的框架而已)
app.get('/',function(req,res) {
// 怎么把url改成是访问www.test.com/index.html呢?
// 这个问题应该不是用express.static()来解决吧?
});
PHP中文网2017-04-17 11:58:53
The default index.html, otherwise why do you think the homepage is named this? Express seems to be its own web server, and you can access index silently
ringa_lee2017-04-17 11:58:53
If you are using express, after creating a template with express, there will be an index.js file in the /router directory. The code inside defines the default page after accessing www.example.com/. The code is as follows
/*
* GET home page.
*/
exports.index = function(req, res){
res.render('index', { title: 'Express' });
};
'index' is a template, go to the /views folder to check it out.