#How to Use Next.js Frontend with Gin/Go Backend/Server?
1 messages · Page 1 of 1 (latest)
🔎 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)
I would just use something like axios to make requests to your back end. Create a client.js file which initializes the axios client with a base url and any other configuration you need, then in a separate file, create a wrapper function for each endpoint you have which invokes that endpoint using the axios client you've created
Keep in mind, you will end up with two separate servers running: one for your Go/Gin api and one for your next.js server. Any getServerSideProps or getStaticProps code you write will run on the next.js server and will need to be coded in javascript. This may mean you need to add javascript wrappers for your data layer on your next.js server as well if you need to access that data in order to render the page
In this setup, your next.js server and go server would both be accessing your data layer independently - the next.js server just for any data that is needed to render pages, and the go server for any data needed for any of your api endpoints
Thanks for the answer, but I am specifically looking for an answer that involves Go. This does not cut it.
I have been following this tutorial here but getting some errors: https://webapp.io/blog/nextjs-with-golang/
If you want a scalable, high-performance backend with a fast-loading frontend, this guide is for you. Let's introduce our technologies: Go is a backend language which has been tremendously popular since being launched by Google 10 years ago. It's simple to learn, has powerful concurrency primitives, and can deploy anywhere
I'm also looking to use a Go framework, namely Gin, for my web app development. So I'm following this tutorial here: https://gin-gonic.com/docs/quickstart/
In this quickstart, we’ll glean insights from code segments and learn how to:
Requirements Go 1.16 or above Installation To install Gin package, you need to install Go and set your Go workspace first.
Download and install it: $ go get -u github.com/gin-gonic/gin Or install:
$ go install github.com/gin-gonic/gin@latest Import it in your code: imp...
Oops let me be more specific.
When inside @/services/backend I'm running the following in order to install the Gin framework for Go:
go install github.com/gin-gonic/gin@latest
...and getting the following error:
package github.com/gin-gonic/gin is not a main package
Update: Managed to install the Gin framework, however, the last step in the "How to use NextJS with Golang" article I sent is incorrect; specifically, the way to connect the Next frontend with the Golang backend. There is no longer a @/pages/index.js. How do I fix this?
Hey @cedar anvil are you online? I was hoping you could help me out with this
Do not ping other people in order to get attention to your question unless they are actively involved in the discussion. If you're looking to get help, it is a lot better to post your question in a public channel so other people can help or learn from the questions.
Okay my bad I won't do that again
@ivory delta
wassup
i am quite literally your savior xD
one sec
Thats a nextjs + golang monorepo
https://github.com/Arinji2/garconia
Vite frontend + Golang backend + Discord.go monorepo
I am working on a new project rn, you could also check that out
https://github.com/Arinji2/vocab-thing
cmd/api is the golang api
cmd/web is the nextjs website
This repo will also have a chrome and firefox extensions code which will be in cmd/extensions
It also has a sqlite setup with migrations from goose
choose whatever you want
You quite literally are my savior! Thanks a bunch 
I will go through these repos as fast as possible
Sure thing, I'm also learning go as well (been a year or so) so I am still trying to figure out how to structure my go apps specifically.
The newest repo I think has the best structure wrt a rest api
Have you used Next.js with the Go framework Gin?
No.. I use the go chi router or just basic net/http
@ivory delta any updates?
I will let you know if there is any, I had to spend the past two days doing some work as I had just come back from an international trip. I will mark as complete for now and update you if I have any questions.
This question has been marked as answered! If you have any other questions, feel free to create another post
[Click here](#1349764038665441330 message)
Imma unfollow the post.. ping me if you have other questions