Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async render (renderContext) {
const { url = '/', req = {}, _generate } = renderContext
const modernMode = this.options.modern
const modern = (modernMode && _generate) || isModernRequest(req, modernMode)
const cacheKey = `${modern ? 'modern:' : 'legacy:'}${url}`
let meta = this.cache.get(cacheKey)
if (meta) {
// Return a copy of the content, so that future
// modifications do not effect the data in cache
return cloneDeep(meta)
}
meta = {
HTML_ATTRS: '',
HEAD_ATTRS: '',
BODY_ATTRS: '',
HEAD: '',
BODY_SCRIPTS_PREPEND: '',
BODY_SCRIPTS: ''
// Add url to the renderContext
renderContext.url = url
const { req = {} } = renderContext
// renderContext.spa
if (renderContext.spa === undefined) {
// TODO: Remove reading from renderContext.res in Nuxt3
renderContext.spa = !this.SSR || req.spa || (renderContext.res && renderContext.res.spa)
}
// renderContext.modern
if (renderContext.modern === undefined) {
const modernMode = this.options.modern
renderContext.modern = modernMode === 'client' || isModernRequest(req, modernMode)
}
// Call renderContext hook
await this.serverContext.nuxt.callHook('vue-renderer:context', renderContext)
// Render SPA or SSR
return renderContext.spa
? this.renderSPA(renderContext)
: this.renderSSR(renderContext)
}
async middleware (req, res, next) {
const name = isModernRequest(req, this.buildContext.options.modern) ? 'modern' : 'client'
if (this.devMiddleware && this.devMiddleware[name]) {
await this.devMiddleware[name](req, res)
}
if (this.hotMiddleware && this.hotMiddleware[name]) {
await this.hotMiddleware[name](req, res)
}
next()
}