Issue with the middleware matcher
Answered
gin posted this in #help-forum
ginOP
So im trying to match all request except /ocelot/evidence/:id
In my nextconfig i have basepath set as /ocelot so when a user goes on domain.com/ocelot for my nextapp it will be only domain.com/
this should be correct right?
export const config = {
matcher: [
"/((?!^/ocelot/evidence/\\d+$).*)",
],
};const nextConfig = {
basePath: "/ocelot",
compiler: {
styledComponents: true,
}, images: {
remotePatterns: [
{
protocol: "http",
hostname: "**",
},
{
protocol: "https",
hostname: "**",
},
],
},
env: {
COMMIT_HASH,
COMMIT_DATE,
}
}In my nextconfig i have basepath set as /ocelot so when a user goes on domain.com/ocelot for my nextapp it will be only domain.com/
this should be correct right?
60 Replies
ginOP
now my issue is that my matcher only matches /ocelot/ocelot even tho it should also match /ocelot
if i go on http://localhost:3000/ocelot my logs show me
http://localhost:3000/ocelot/_next/static/chunks/webpack.js?v=1716670501873
http://localhost:3000/ocelot/_next/static/chunks/main-app.js?v=1716670501873but not the path itself
only the assets
its weird its like my app doesnt recognize the path even tho its rendering the layout
it doesnt recognize the /ocelot path but every other like /ocelot/123
export const config = {
matcher: ["/((?!api|_next/static|_next/image|favicon.ico).*)"],
};even after this it still doesnt work
i could use conditional statements but how if request.nextUrl.pathname returns null
ginOP
bump
ginOP
bump
ginOP
bump
Lemme see
@gin I think it should be
/ocelot/path/**/*@Anay-208 <@759064479521701888> I think it should be `/ocelot/path/**/*`
ginOP
my matcher should match everything
Can you try what i told you?
@Anay-208 <@759064479521701888> I think it should be `/ocelot/path/**/*`
ginOP
where i put that?
i didnt explain it correctly look bro,
in my config i have
now when i go on:
http://localhost:3000/ocelot
middleware doesnt recognize the request even tho i have this in matcher
when i go on http://localhost:3000/ocelot/123
i get logged
thats correct!
basePath: "/ocelot",now when i go on:
http://localhost:3000/ocelot
middleware doesnt recognize the request even tho i have this in matcher
console.log(request.nextUrl.pathname);
export const config = {
matcher: ["/((?!api|_next/static|_next/image|favicon.ico).*)"],
};when i go on http://localhost:3000/ocelot/123
i get logged
/123thats correct!
@Anay-208
when i remove basePath from config it works
the problem is my whole app needs to be on the /ocelot path because i have other apps runing on /123
example.
@gin <@755810867878297610>
Mark the message which solved your question as answer
@Anay-208 Mark the message which solved your question as answer
ginOP
it didnt solve it
😭
thats the problem i have
@gin the problem is my whole app needs to be on the /ocelot path because i have other apps runing on /123
Remove ocelot on matching then
@Anay-208 Remove ocelot on matching then
ginOP
nono, i have to match ocelot
everything that is on /ocelot
domain.com/ocelot is for nextjs just /
because of the basepath
but that / is not matched
thats my problem
its not detected even tho my page is still rendered on /
@gin nono, i have to match ocelot
Try removing it since basePath is ocelot
@Anay-208 Try removing it since basePath is ocelot
ginOP
remove what?
this is matching everything right
export const config = {
matcher: ["/((?!api|_next/static|_next/image|favicon.ico).*)"],
};this is matching everything right
so it should also match /
but its not
i had this issue before aswell
i kinda fixed it with some thirdparty router for the middlewarew
but i dont want to use that
yeah i was using this https://www.npmjs.com/package/next-connect
ginOP
its not fixing btw
ginOP
bump
ginOP
bump
ginOP
bump
ginOP
bump
ginOP
bump
American Crow
just a heads up mods will ban you if you bump more than once a day
@American Crow just a heads up mods will ban you if you bump more than once a day
ginOP
where does it say that
try to help me, its important
Original message was deleted
ginOP
alr
ginOP
bump
ginOP
bumpuus
ginOP
this fixed my issue
@gin https://github.com/vercel/next.js/issues/47085#issue-1621947306
ginOP
@Anay-208 if you need this at any time have a look at this
this was the fix
export const config = {
matcher: [
'/((?!api|_next/static|_next/image|favicon.ico).*)',
{ source: '/' },
]
}