Answer the question
In order to leave comments, you need to log in
SSR on Express.js and vue.js. How does server.get('*', function (request, response){} work?
I'm interested in this line:
// Handle all GET requests
server.get('*', function (request, response) {
// Render our Vue app to a string
renderer.renderToString(
// Create an app instance
require('./assets/app')(),
// Handle the rendered result
function (error, html) {
// If an error occurred while rendering...
if (error) {
// Log the error in the console
console.error(error)
// Tell the client something went wrong
return response
.status(500)
.send('Server Error')
}
// Send the layout with the rendered app's HTML
response.send(layout.replace('<div id="app"></div>', html))
}
)
})
Answer the question
In order to leave comments, you need to log in
Is this the code from here? ;) https://vuejs.org/v2/guide/ssr.html
This is just a demo, requests are not processed in it, for any line [because get('*', ] in the URL the server will return the same HTML.
To handle specific requests, you need to add new server.get('/requestXXX', etc.
see expressjs.com/ru/guide/routing. html
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question