#Help with SSR

98 messages Β· Page 1 of 1 (latest)

slim ledgeBOT
#

πŸ”Ž This post has been indexed in our web forum and will be seen by search engines so other users can find it outside Discord

πŸ•΅οΈ Your user profile is private by default and won't be visible to users outside Discord, if you want to be visible in the web forum you can add the "Public Profile" role in id:customize

βœ… You can mark a message as the answer for your post with Right click -> Apps -> Mark Solution
(if you don't see the option, try refreshing Discord with Ctrl + R)

storm cobalt
#
  1. you cannot use useEffect in server component
  2. you are using useEffect without importing it
crisp turtle
storm cobalt
#

just call connectDB directly

crisp turtle
storm cobalt
#

home component can be async

crisp turtle
#

hey i think its working

#

so ik the folder structure plays an important role in next
say i wanna fetch data from db and work on servers should those files be put in some separate folders??

storm cobalt
crisp turtle
storm cobalt
crisp turtle
storm cobalt
#

there is no getServerSideProps nor getStaticProps in app router

crisp turtle
#

thanks and whats app router 😭

storm cobalt
crisp turtle
#

ohh so i cant use ssrprops when using that?

storm cobalt
#

getServerSideProps and getStaticProps are for page router which use pages folder

storm cobalt
crisp turtle
#

right does that mean im good using just callback functions??

storm cobalt
#

just execute the function in the component

crisp turtle
#

right

storm cobalt
#

by default, the component is a server component

crisp turtle
#

lets say my main page is a client comp can i declare a function in there as a server??

crisp turtle
storm cobalt
#

it is better to leave the page as server component because metadata api need to be used with server component

crisp turtle
#

uhhh

#

can i dm?

storm cobalt
#

better not, I have lot of unread dmlolsob

crisp turtle
#

im really confused and excited at the same time lol

storm cobalt
crisp turtle
#

alright lolsob

#

why doesnt it get passed as props??

storm cobalt
#

what is that

#

man it isn't how nextjs work

crisp turtle
storm cobalt
#

you don't need getProps()

crisp turtle
crisp turtle
storm cobalt
#

npx create-next-app@latest and choose no when it ask do you want to use app router

crisp turtle
#

I’ll let yk if there anything else

crisp turtle
#

Help with SSR [Solved]

slim ledgeBOT
#
βœ… Success!

This question has been marked as answered! If you have any other questions, feel free to create another post

Jump to answer
vale pond
#

please do not delete the question after it has been answered because (1) the answer will look awkward without the context and (2) other people cannot benefit from the answer as well. if your question includes sensitive data, you should edit the question to remove it instead (but you should never reveal any sensitive data in public forums like this one)

crisp turtle
#

Help with SSR

#

whenever i call the signup route it says 404 not found

storm cobalt
crisp turtle
#

i switched to app router and some server error

summer badge
#

Can you show how you switched to the App router?

crisp turtle
storm cobalt
summer badge
crisp turtle
crisp turtle
summer badge
crisp turtle
#

wait a min

summer badge
#

Also, why is your page.js a client component?

crisp turtle
#

um i was using some hooks earlier so i changed it back then

summer badge
#

That doesn't show the error shown in the console. You're also not helping yourself by not using TypeScript

crisp turtle
summer badge
#

Are you in a competition or something? Or is this for school or something?

crisp turtle
#

Im in college and this is a task given for me by a company

#

like inorder for me to get placed or hired i must clear their rounds and tasks

summer badge
#

Either way, I would use server actions instead of creating internal API routes.

#

Server actions are just functions that run on the server that you can call both from server and client components.

storm cobalt
# crisp turtle
const reqBody = await NextRequest.json()

to

export async function POST(req: NextRequest) {
  const reqBody = await req.json()
}
storm cobalt
crisp turtle
storm cobalt
#

NextRequest is a class

storm cobalt
crisp turtle
#

lol dont give up lolsob

storm cobalt
#

you need time to learn

crisp turtle
storm cobalt
#

express is old

#

use hono πŸ‘πŸΎ

crisp turtle
crisp turtle
summer badge
#

I don't think Hono or Express are super relevant here. The app router's API routes really give you what you need here. You just need to be willing to read the documentation or the course.

crisp turtle
summer badge
#

Don't rush into a job just for the sake of getting a job

#

The task for won't be easier just because you're paid to do it

crisp turtle
summer badge
#

It won't be a very good experience for anyone if you get fired

crisp turtle
#

aight thanks TxT

crisp turtle
summer badge
#

nice

crisp turtle
#

So how can I limit the route.. like I want to allow /login/ok only when username and password are correct