How to use the @nuxt/utils.isModernRequest function in @nuxt/utils

To help you get started, we’ve selected a few @nuxt/utils examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github nuxt / nuxt.js / packages / vue-renderer / src / renderers / spa.js View on Github external
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: ''
github nuxt / nuxt.js / packages / vue-renderer / src / renderer.js View on Github external
// 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)
  }
github nuxt / nuxt.js / packages / webpack / src / builder.js View on Github external
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()
  }