5

I'm trying to work with the new edge functions from Vercel next.js and it's not working on production, always gives a 404 error.

I followed this example and nothing works.

maybe because I'm using i18n?

my _middleware.js file looks like this:

import {NextResponse } from 'next/server'

export default function middleware(req) {
    const { pathname } = req.nextUrl
    let hostname = req.headers.get('host')


if (
    !pathname.includes('.') && // exclude all files in the public folder
    !pathname.startsWith('/api') // exclude all API routes
) {
    if (
        !hostname.includes('example.vercel.app') &&
        hostname !== 'example.com' &&
        hostname !== 'localhost:3000'
    ) {
        return NextResponse.rewrite(`/_sites/${hostname}${pathname}`)
    }
}
}

And under pages I'm using this structure:

/pages
 /_sites
  [sites]
    index.js

Please help me find a solution for that.

juliomalves
  • 42,130
  • 20
  • 150
  • 146
Avichay Dahan
  • 79
  • 1
  • 4

0 Answers0