Skip to content

Commit

Permalink
fix: redirect using url config key (#256)
Browse files Browse the repository at this point in the history
  • Loading branch information
94726 authored Jun 24, 2024
1 parent 4b74d99 commit 2f195e4
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/runtime/nitro/middleware/redirect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ import { useNitroOrigin, useSiteConfig } from '#imports'

export default defineEventHandler((e) => {
const siteConfig = useSiteConfig(e)
if (siteConfig.site) {
const siteConfigHostName = new URL(e.path, siteConfig.site).hostname
if (siteConfig.url) {
const siteConfigHostName = new URL(e.path, siteConfig.url).hostname
const origin = useNitroOrigin(e)
const originHostname = new URL(e.path, origin).hostname
// if origin doesn't match site, do a redirect
if (originHostname !== siteConfigHostName)
return sendRedirect(e, joinURL(siteConfig.site, e.path), 301)
return sendRedirect(e, joinURL(siteConfig.url, e.path), 301)
}
})

0 comments on commit 2f195e4

Please sign in to comment.