node.js - Don't understand res.sendFile(path.resolve('./public'))
漂亮男人
漂亮男人 2017-06-05 11:13:38
0
3
873

This is my code structure

I used this code in app.js so that my index.html and movieDetail.html can be accessed, but I don’t know what this code means. Please answer

app.use('*', function (req, res) {
   res.sendFile(path.resolve('./public'));
 })
漂亮男人
漂亮男人

reply all(3)
为情所困

This statement is equivalent to all requests coming in, searching for the requested file in the current public directory of the project, and returning it when found. Your indez.html and movieDetail.html are in the public directory, and of course they will be returned

我想大声告诉你

The route is parsed to the corresponding html page under public

曾经蜡笔没有小新

All are contents of the express framework, please refer to the official documents http://expressjs.com/en/4x/ap... and http://expressjs.com/en/4x/ap... . Simply put, the meaning of this code is to match all routes and return the specific file under the public path after receiving the request.
You can also read the Chinese documentation: http://www.expressjs.com.cn/4... and http://www.expressjs.com.cn/4...

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