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'));
})
为情所困2017-06-05 11:15:38
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
曾经蜡笔没有小新2017-06-05 11:15:38
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...