Skip to content

This project demonstrates the setup for deploying a react client application and a Go server in a same instance.

License

Notifications You must be signed in to change notification settings

Sahil2k07/React-Go

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

React-Go

This repository demonstrates how a Golang backend and a React Single Page Application (SPA) frontend can be deployed together on a single cloud instance.

🛠️ Tech Stack

  • Backend: Go with Echo
  • Frontend: React (built with Vite) and Bun for development
  • Build Tool: Makefile to streamline build and deployment processes

🚀 Deployment

  • The frontend is built and the static files are placed in the public/ folder.
  • The Go server serves both the API routes and the static frontend files from the same binary.
  • Suitable for deploying on a single VM/cloud instance (e.g., EC2, Droplet, etc.)

SPA Snippet

    e := echo.New()

	e.Use(middleware.CORSWithConfig(middleware.CORSConfig{
		AllowOrigins:     []string{"http://localhost:5173"},
		AllowMethods:     []string{http.MethodGet, http.MethodPost, http.MethodPut, http.MethodDelete},
		AllowCredentials: true,
	}))

	e.Use(middleware.Logger())
	e.Use(middleware.Recover())

    // Map the controllers before the static files

	e.Static("/", "public")
	e.File("/", "public/index.html")

	e.Logger.Fatal(e.Start(":1323"))

Try it out

  1. Clone the repository

    git clone https://github.com/Sahil2k07/React-Go.git
  2. Change Directory

    cd React-Go
  3. Make the build using the Makefile

    make
  4. Run the project

    make run

    or

    cd build
    ./React-Go
  5. The application will listen on http://localhost:1323

⚙️ Notes

  • Ensure CORS is correctly configured in Echo when running frontend and backend separately during development.

  • You have make installed. Use the command to install make on your Ubuntu machine

    sudo apt-get install make
  • In production, everything is served from the same Go server to avoid CORS issues.

About

This project demonstrates the setup for deploying a react client application and a Go server in a same instance.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published