node.js - nodejs如何访问/返回/index.html
怪我咯
怪我咯 2017-04-17 11:56:53
0
2
651

遇到express.static()方法, 但是有点不懂它到底是怎么用的.

思考到的一个问题是,访问一个网站的时候,例如www.test.com,他是怎么把url改成www.test.com/index.html的?

给一下我的认为的代码吧(一个大致的框架而已)

app.get('/',function(req,res) {
    // 怎么把url改成是访问www.test.com/index.html呢?
    // 这个问题应该不是用express.static()来解决吧?
});
怪我咯
怪我咯

走同样的路,发现不同的人生

reply all(2)
Ty80

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

左手右手慢动作

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.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template