Trying to display page views with redis
Answered
Singapura posted this in #help-forum
SingapuraOP
"Warning: Detected multiple renderers concurrently rendering the same context provider. This is currently unsupported."
I keep getting this error and then in my console getting an error with api/view/route on not being found.
I keep getting this error and then in my console getting an error with api/view/route on not being found.
Answered by risky
yeah make sure to use nextjs response
import { NextResponse } from 'next/server'
export async function GET() {
return NextResponse.json({ hello : "world"})
}
37 Replies
risky
you should simplify your code, and make seperate functions for the diferent methods: https://nextjs.org/docs/app/building-your-application/routing/route-handlers#convention
i don't think you can just export handler like that...
SingapuraOP
Thx for replying, refactored it to separate the GET and POST methods into different functions, still getting the same error
risky
you request it as
POST
or GET
/api/view
(no /route is needed)also, im assuming you don't want it to increment on the footer, and just show the amount of views
Barbary Lion
@Singapura write return before res.json or res.status
risky
yeah make sure to use nextjs response
import { NextResponse } from 'next/server'
export async function GET() {
return NextResponse.json({ hello : "world"})
}
Answer
SingapuraOP
Yup you're just right just show the total views like Rauch's blog (https://rauchg.com/)
Barbary Lion
@Singapura also use phind.com it will be way faster in helping
risky
pls don't recommend AI, if you want to, at least use #gpt-help because nextjs team trusts it and makes sure its trained on latest docs
SingapuraOP
Yes I've been using cursor.so with the latest nextjs 13 docs
Thx for the suggestion @Barbary Lion
Barbary Lion
Phind pulls lastest docs, doesn't usually hallucinate
SingapuraOP
I'll check it out, let me modify it with the nextjs response first
I'm not getting any errors but the views aren't updating at every refresh
risky
where are you running the post req?
Barbary Lion
Add console logs to see what code gets executed
In both methods
risky
the code provided in second screenshot only shows them using get request, so im wondering where it gets incremented
Barbary Lion
Also is redis locally hosted? You can't do that with a edge function. Try using a service that hosts a redis instance for you
SingapuraOP
risky
can we also pls not assume more than nessary... not all devs want to use vercel... a decent amount want to self host, where redis is good + they could be connecting to serverless redis host anyway
SingapuraOP
Should I deploy it? I'm using upstash redis and it's showing in the dashboard that it's reading
risky
i still don't see wher you are either calling the post req ore incremening it server side
SingapuraOP
It should be showing up here
Ok so that's probably the issue that the Post request to increment the views is not called anywhere
risky
yeah
SingapuraOP
Ahhhhhhhh
thank you so much
Sorry for the questions transitioning from design to dev
It's working ðŸ™
risky
yay!
Barbary Lion
Are you making this thing by yourself
risky
lol i didn't even relise that it was an ai product...
SingapuraOP
Lol nah getting some help from a friend
Mainly doing front-end/ux/sales
But trying to help where I can