- asyncData runs on the server, cannot be requested with ajax, is already running on the server, and does not require ajax.
- you cannot require mongo a database in entry-server.js,
- where should I execute the query command of mongodb and send the data to asyncData?
- is it possible to put data into context in front of the render page?
const baseRender = async function(ctx, next){
let context = {url: ctx.request.url};
let htmlStr = await new Promise((resolve, reject) => {
renderer.renderToString(context, (err, html) => {
if (err) {
reject(err)
}
resolve(html);
});
}).catch(e => {
console.error(e);
return e;
});
if (htmlStr.code && htmlStr.code === 404) {
await next();
} else {
ctx.body = htmlStr;
}
}