Skip to content

Recipe: Document redirects #122

Open
@atinux

Description

@atinux

It is important to handle redirects for the production website to avoid having the .pages.dev alias and automating it might not be the best way.

This is one example:

const DOMAIN = 'admin.hub.nuxt.com'

export default defineEventHandler(async (event) => {
  const host = getRequestHost(event)
  if (import.meta.prerender || import.meta.dev || ['localhost', DOMAIN].includes(host)) {
    return
  }

  if (useRuntimeConfig().hub.env === 'production') {
    return sendRedirect(event, 'https://' + DOMAIN + event.path, 301)
  }
})

Metadata

Metadata

Assignees

No one assigned

    Labels

    documentationImprovements or additions to documentation

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions