A web forum built with React and Golang.
You can find the live version of the project here. Postman API here. You can find the frontend here and its repository here.
Name: Loh Jian Rong
Matric No.: A0252735A
- Clone the reponsitory.
$ git clone [email protected]:jianrong7/cvwo-be.git
- Copy template env file (
.env.example
).
PORT=3000 # Port number that your server will listen to
DB_URI=YOUR_DB_URI # PostgreSQL DB_URI
# SAMPLE_DB_URI=postgres://USER:PASSWORD@localhost:5432/DB_NAME
JWT_SECRET=YOUR_JWT_SECRET # Random string to sign JWT Tokens
OPENAI_API=YOUR_OPENAI_API # OpenAI API Key to fetch AI generated posts
AWS_ACCESS_KEY_ID=YOUR_AWS_ACCESS_KEY # AWS S3 Key for uploading of profile pictures
AWS_SECRET_ACCESS_KEY=YOUR_AWS_SECRET_ACCESS_KEY # AWS S3 Key for uploading of profile pictures
AWS_DEFAULT_REGION=YOUR_AWS_DEFAULT_REGION # AWS S3 Key for uploading of profile pictures
- Run the server!
<!-- If you have gin set up, you can use hot reload. -->
$ gin
<!-- If not, the default command would be. -->
$ go run main.go
- Gin with Golang for backend framework
- GORM for object relational mapping
- AWS SDK to upload images to S3
- OpenAI SDK to connect with OpenAI
- bcrypt to hash password
backup.sh # Cron job to backup PostgreSQL database onto the EC2 instance.
controllers # Handles GET, POST, PUT, DELETE logic.
initializers # Connect database, load environment variables, start AWS and OpenAI clients.
middleware # Contains the CORS middleware as well as the authentication middlware.
models # Contains the models as defined by the database schema.
routes # Contains routes to endpoints, separated by respective entities.
utils # Contains JWT related functions.
docker-compose.yml # Dockerize application and start database image simultaneously.
Dockerfile # To dockerize application.
main.go # Main app file
This app is deployed on an AWS EC2 instance. As I do not have a custom domain and I do not want to pay for one, I used a workaround to obtain HTTPS support. Since the AWS EC2 instance did not allow us to generate SSL certificates, I made use of Caddy to create a reverse proxy. This web server is also handy in giving automatic HTTPS support. That way, I do not need a custom domain for HTTPS support, albeit sacrificing the "niceness" of the URL.