Middleware not getting executed for root domain
Answered
Mrigal carp posted this in #help-forum
Mrigal carpOP
i am building a simple multi tenant architecture. Even tried upgrading to latest "next": "^13.4.12" from 13.1. Having old pages folder and not been moved to app structure.
I have localhost:3000 to render my app home page and site1.localhost:300, site2.localhost:3000 etc for customer sites.
Whenever i try root domain ( localhost:3000, site1.localhost:3000 or site2.localhost:3000 ) the middleware code is not getting executed.
Even tried simple print statement, but not getting printed.
export default async function middleware(req: NextRequest) {
const url = req.nextUrl;
console.log("HEEEEE")
}
Whenever i add something more to url like /blog, i can see it getting executed.
I am trying to render different homepages 🙂
Thank you
I have localhost:3000 to render my app home page and site1.localhost:300, site2.localhost:3000 etc for customer sites.
Whenever i try root domain ( localhost:3000, site1.localhost:3000 or site2.localhost:3000 ) the middleware code is not getting executed.
Even tried simple print statement, but not getting printed.
export default async function middleware(req: NextRequest) {
const url = req.nextUrl;
console.log("HEEEEE")
}
Whenever i add something more to url like /blog, i can see it getting executed.
I am trying to render different homepages 🙂
Thank you
Answered by Rafael Almeida
try adding a separate one for
'/' at the start of the array11 Replies
how does your exported
config variable look like?Mrigal carpOP
export const config = {
matcher: [
/*
* Match all paths except for:
* 1. /api routes
* 2. /_next (Next.js internals)
* 3. /_static (inside /public)
* 4. all root files inside /public (e.g. /favicon.ico)
/
"/((?!api/|_next/|_static/|_vercel|[\w-]+\.\w+).)",
],
};
matcher: [
/*
* Match all paths except for:
* 1. /api routes
* 2. /_next (Next.js internals)
* 3. /_static (inside /public)
* 4. all root files inside /public (e.g. /favicon.ico)
/
"/((?!api/|_next/|_static/|_vercel|[\w-]+\.\w+).)",
],
};
try adding a separate one for
'/' at the start of the arrayAnswer
Mrigal carpOP
Earlier i had // export const config = { matcher: ['/'] }
while debugging i copied platofrm starter kit one
to see if that works
@Rafael Almeida Added / as you said
Working now.
oh great!
Mrigal carpOP
Thank you for the quick help.
ðŸ™