Next.js Discord

Discord Forum

Serving -H accept text/plain with the app router

Unanswered
Devon Rex posted this in #help-forum
Open in Discord
Devon RexOP
I want to serve my non-api endpoint with raw text if it's the header dictates so. GetServerSideProps is gone and I can't just return a Response in the page, so how do i go about it?

6 Replies

Try middleware
@joulev Try middleware
Devon RexOP
there's no route specific middlewares right? i only want this for one route
oh there's config const
Devon RexOP
export const config = {
matcher: ['/:id*']
}

is what i have for the middleware to only work for app/[id]/page.tsx, but it seems to catch other routes as well
@Devon Rex js export const config = { matcher: ['/:id*'] } is what i have for the middleware to only work for `app/[id]/page.tsx`, but it seems to catch other routes as well
well, your matcher needs to be a lot stricter than that. i don't really remember how to write matchers, nor do i know regex well enough, but middleware doesn't know about your app routing structure. it doesn't know there is a dynamic route app/[id]/page.tsx. it only knows there is an incoming request and the request has a particular pathname that's all
you need to e.g. exclude /_next requests, exclude static file requests, exclude other pages, etc. all kind of things