API routes triggering ERR_TOO_MANY_REDIRECTS
Answered
Scottish Fold posted this in #help-forum
Scottish FoldOP
I have an API route that simply fetches from a Prisma database and returns it as JSON using SWR, but I can see in my browser console that it's failing with
It also doesn't appear to be happening on my production Railway deployments. I've tried deleting pnpm-lock.yaml, node_modules, and .next but nothing seems to be working. Any ideas?
ERR_TOO_MANY_REDIRECTS, but I don't know why, it just started happening. It also doesn't appear to be happening on my production Railway deployments. I've tried deleting pnpm-lock.yaml, node_modules, and .next but nothing seems to be working. Any ideas?
62 Replies
Scottish FoldOP
@Scottish Fold I have an API route that simply fetches from a Prisma database and returns it as JSON using SWR, but I can see in my browser console that it's failing with `ERR_TOO_MANY_REDIRECTS`, but I don't know why, it just started happening.
It also doesn't appear to be happening on my production Railway deployments. I've tried deleting pnpm-lock.yaml, node_modules, and .next but nothing seems to be working. Any ideas?
are you getting the
ERR_TOO_MANY_REDIRECTS error in dev?or on prod
Scottish FoldOP
in dev
let me test it in prod on my machine
how do you fetch the data? do you have a middleware?
Scottish FoldOP
using SWR
no middleware
it is happening in prod
next start@Scottish Fold using SWR
could you show the code on how you are fetching?
if no middleware, could you show your
next.config.js tooScottish FoldOP
@Scottish Fold Click to see attachment
can you try to comment out the
redirects() and see if you still get the error?Scottish FoldOP
sure
still happening
@Scottish Fold still happening
try ctrl+F5 on window or cmd + shift + r
Scottish FoldOP
alr
no luck
@Scottish Fold no luck
try comment out everything on
Games() and just return <div>Games</div>Scottish FoldOP
okay
still occurring
@Scottish Fold still occurring
so the problem is not from swr
Scottish FoldOP
oh wait comment out the SWR hook as well?
nor the api
yes
Scottish FoldOP
okay
then it doesn't happen
just displays games
@Scottish Fold just displays games
oh ok revert it back
Scottish FoldOP
alright
yeah so when I add the swr section back it comes back
and add this above the
if (error) {if (isLoading) return <div>loading...</div>Scottish FoldOP
ok
yeah still errored
@Scottish Fold yeah so when I add the swr section back it comes back
how does the
fetcher look like?Scottish FoldOP
@Scottish Fold Click to see attachment
could you try without million?
Scottish FoldOP
yeah
no luck
oh
could you share the repo?
Scottish FoldOP
yes one moment
@Scottish Fold https://github.com/art-class/v5
ok could you try to rename the
pages folder to _pagesScottish FoldOP
yes
nope
@Scottish Fold nope
doesn't work?
Scottish FoldOP
does not work
@Scottish Fold does not work
I don't see redirect when it run on my machine
have you tried with different browser?
Scottish FoldOP
No, let me try
alright, its working in a different browser
so it is a me issue
clear the browser cache
open dev tools > network tab > tick Disable cache
Answer
Scottish FoldOP
okay
then access the page and you can uncheck Diable cache
Scottish FoldOP
that's working now
thank you
np