Next.js Discord

Discord Forum

Make some routes, ie. /dev, /testing, available only in development?

Answered
Dwarf Crocodile posted this in #help-forum
Open in Discord
Dwarf CrocodileOP
I'm essentially trying to have /dev only be available while running the dev server, and not be available in the production build.

Is this possible? Perhaps through some middleware shenanigans?

Appreciate any and all help :JinxHeart:
Answered by B33fb0n3
yes, you can do this thought a middleware. Create the middleware add the matcher and configure the matcher, so it only matches on the routes, that you want to protect.

After that you can do whatever you want to do: show them 404. Redirect them. ...
View full answer

3 Replies

@Dwarf Crocodile I'm essentially trying to have `/dev` only be available while running the dev server, and **not** be available in the production build. Is this possible? Perhaps through some middleware shenanigans? Appreciate any and all help <:JinxHeart:939592567694164009>
yes, you can do this thought a middleware. Create the middleware add the matcher and configure the matcher, so it only matches on the routes, that you want to protect.

After that you can do whatever you want to do: show them 404. Redirect them. ...
Answer
Dwarf CrocodileOP
Alright thanks :)
sure thing