structure
Answered
harman posted this in #help-forum
harmanOP
how to structure your folders and files in nextjs and also API base url where to keep that for common use and how to make middleware file in nextjs so that i get data in json and add token in api headers. I am new to development so please help me
Answered by B33fb0n3
in nextjs you can use env variables. There you define a new variables (in your
.env) and this variable can be access serverside everywhere. Or if you even add the prefix NEXT_PUBLIC to it, even your client cana access it by using process.env.NEXT_PUBLIC_YOUR_VARIABLE_NAME8 Replies
@harman how to structure your folders and files in nextjs and also API base url where to keep that for common use and how to make middleware file in nextjs so that i get data in json and add token in api headers. I am new to development so please help me
you can find some common approaches directly here: https://nextjs.org/docs/app/building-your-application/routing/colocation#project-organization-strategies
I personally like to structure it like this:
I personally like to structure it like this:
harmanOP
Could you please share file with me crud.ts and fetcher.ts
I want to check the code as how to give api url and other things
I want to check the code as how to give api url and other things
@B33fb0n3
@harman Could you please share file with me crud.ts and fetcher.ts
I want to check the code as how to give api url and other things
you can ignore the
C: create
R: read
U: update
D: delete
The auth via a data access layer (that does not exists yet).
fetcher.ts. crud.ts is a file where all useful functions are in ,that don't require anything (auth, filtering, ...). It's justC: create
R: read
U: update
D: delete
The auth via a data access layer (that does not exists yet).
harmanOP
@B33fb0n3
I want to keep my API base url somewhere which file we can use common in all pages.
Like in angular we have service which we can use in any component like that where that file I can generate and how to use in others
I want to keep my API base url somewhere which file we can use common in all pages.
Like in angular we have service which we can use in any component like that where that file I can generate and how to use in others
@harman <@301376057326567425>
I want to keep my API base url somewhere which file we can use common in all pages.
Like in angular we have service which we can use in any component like that where that file I can generate and how to use in others
in nextjs you can use env variables. There you define a new variables (in your
.env) and this variable can be access serverside everywhere. Or if you even add the prefix NEXT_PUBLIC to it, even your client cana access it by using process.env.NEXT_PUBLIC_YOUR_VARIABLE_NAMEAnswer
harmanOP
okay yes env file got it. thanks
happy to help