This is a template project to use golang with gin and react as monolith application easier for Full Stack Developer. Don't need to deploy frontend and backend as separate service, gin will serve static content from React either it is on development (with hot reload) or production.
- Golang v1.16
- Node Js v14
- Clone the repository from Github
- Add
.envfile in root directory of this projectThe template for `.env` file can be found at `.env.example`. - Install backend and frontend dependencies, use
make init - Or if you want to install backend dependencies only, use
make init-server - And if you want to install frontend dependencies only, use
make init-client
Both backend and frontend will served by hot reload, so when change the code and then save file, backend or frontend will restart automatically.
- To run backend only, open new terminal and run
freshat root folder - To run frontend and backend concurrently, open terminal and run
make runat root folder
It will run on localhost:3000 for the frontend, and localhost:3000/api/v1 for the backend, it depends on what port was set in the ENV
- Build the frontend and backend by
make build - Run the build version inside
binfolder./bin/app
- Use
HashRoutesfromreact-router-domto avoid conflicted route between react router and gin router - To make client can read the ENV value, you need to add that into
client/config/webpack.config.js
new webpack.DefinePlugin({
'process.env.APPLICATION_SERVER': JSON.stringify(process.env.APPLICATION_SERVER),
'process.env.APP_ENV': JSON.stringify(process.env.APP_ENV),
'process.env.YOUR_ENV_VALUE_TO_BE_READ': JSON.stringify(process.env.YOUR_ENV_VALUE),
}),