From 12b39371dfc403d1dd6a6fe4779758a53db27b5e Mon Sep 17 00:00:00 2001 From: DanglingDynamo Date: Mon, 13 May 2024 00:17:38 +0530 Subject: [PATCH 01/10] feat: setup sandbox --- .env.example | 2 +- Makefile | 5 +- docker-compose.yml | 26 ++++++++++- nginx/nginx.conf | 114 ++++++++++++++++++++------------------------- 4 files changed, 77 insertions(+), 70 deletions(-) diff --git a/.env.example b/.env.example index 4e10764..068107c 100644 --- a/.env.example +++ b/.env.example @@ -25,4 +25,4 @@ URL=url_to_be_sent_to_mail REDIS_HOST=redis REDIS_PORT=6379 -REDIS_DB=0 \ No newline at end of file +REDIS_DB=0 diff --git a/Makefile b/Makefile index 636aebb..670f03c 100644 --- a/Makefile +++ b/Makefile @@ -1,8 +1,8 @@ # Define variables +include .env DOCKER_COMPOSE = docker compose -URI = "host= port= user= password= dbname=devsoc-24-backend" -URI = "host=139.59.71.66 port=5430 user=admin password=d352F68MX2Hdh2pRFWoB3R9yg dbname=devsoc-24-backend" +DB_URI = "host=localhost port=${POSTGRES_PORT} user=${POSTGRES_USER} password=${POSTGRES_PASSWORD} dbname=${POSTGRES_DB} sslmode=disable" # Targets .PHONY: build up down logs restart clean migrate-up migrate-down @@ -41,4 +41,3 @@ help: @echo " logs View logs of Docker containers" @echo " restart Restart Docker containers" @echo " clean Stop, remove containers, and also remove volumes (data)" - @echo " help Display this help message" diff --git a/docker-compose.yml b/docker-compose.yml index fbdd6a9..892dd7a 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,6 +1,5 @@ -version: '3' +# version: "3" -> Deprecated services: - api: build: . ports: @@ -10,3 +9,26 @@ services: env_file: - .env restart: on-failure + postgres: + image: postgres:latest + ports: + - "6500:5432" # cause 5432 is generally used by other postgres servers running + volumes: + - ./postgres_data:/var/lib/postgresql/data + env_file: + - .env + redis: + image: redis:latest + container_name: redis + ports: + - "6379:6379" + env_file: + - .env + nginx: + image: nginx:latest + ports: + - "80:80" # Replace 8080 with the desired port for your application + volumes: + - ./nginx/nginx.conf:/etc/nginx/conf.d/default.conf # Mount your Nginx configuration file + depends_on: + - api # Nginx depends on the API service being available diff --git a/nginx/nginx.conf b/nginx/nginx.conf index 18df840..d7b09a3 100644 --- a/nginx/nginx.conf +++ b/nginx/nginx.conf @@ -1,71 +1,57 @@ -user nginx; # Server block for your application # create a limit -events { - worker_connections 5000; +geo $limit { + default 1; + 10.0.0.0/8 0; + 192.168.0.0/24 0; } -http { - geo $limit { - default 1; - 10.0.0.0/8 0; - 192.168.0.0/24 0; - } - - map $limit $limit_key { - 0 ""; - 1 $binary_remote_addr; - } - - limit_req_zone $limit_key zone=api_limit:10m rate=10r/s; - - server { -# Listen on the port exposed by the container (80 in this example) - listen 80; - http2 on; - server_name devsoc-24-api.codechefvit.com; - gzip on; - gzip_proxied any; - gzip_types text/plain text/css application/json application/javascript; - -# Access log for debugging - access_log /var/log/nginx/access.log; - -# Serve static files from the application directory - location / { - - if ($request_method = 'OPTIONS') { - add_header 'Access-Control-Allow-Origin' 'https://portal.devsoc.codechefvit.com/'; - add_header 'Access-Control-Allow-Credentials' 'true'; - add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS, PUT, DELETE, PATCH'; - add_header 'Access-Control-Allow-Headers' 'DNT,X-CustomHeader,Keep-Alive,Authorization,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type'; - add_header 'Access-Control-Max-Age' 1728000; - add_header 'Content-Type' 'text/plain charset=UTF-8'; - add_header 'Content-Length' 0; - return 204; - } - - add_header 'Access-Control-Allow-Origin' 'https://portal.devsoc.codechefvit.com/' always; - add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS, PATCH, DELETE' always; - add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range' always; - add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range' always; - add_header 'Access-Control-Allow-Credentials' 'true' always; - -# Adjust these settings based on your application's needs - proxy_set_header Host $host; - proxy_set_header X-Real-IP $remote_addr; - proxy_cache_bypass $http_upgrade; - proxy_buffering off; - proxy_cache off; - -# Set the rate limit - limit_req zone=api_limit burst=10 nodelay; - limit_req_status 429; - +map $limit $limit_key { + 0 ""; + 1 $binary_remote_addr; +} -# Forward requests to the application container (change 127.0.0.1 to your API container name if different) - proxy_pass http://api:8080; - } - } +limit_req_zone $limit_key zone=api_limit:10m rate=5r/s; + +server { + # Listen on the port exposed by the container (80 in this example) + listen 80; + http2 on; + gzip on; + gzip_proxied any; + gzip_types text/plain text/css application/json application/javascript; # Access log for debugging access_log /var/log/nginx/access.log; + # Serve static files from the application directory + location /api { + + # CORS + if ($request_method = 'OPTIONS') { + add_header 'Access-Control-Allow-Origin' 'http://localhost:3000'; + add_header 'Access-Control-Allow-Credentials' 'true'; + add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS, PUT, DELETE, PATCH'; + add_header 'Access-Control-Allow-Headers' 'DNT,X-CustomHeader,Keep-Alive,Authorization,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type'; + add_header 'Access-Control-Max-Age' 1728000; + add_header 'Content-Type' 'text/plain charset=UTF-8'; + add_header 'Content-Length' 0; + return 204; + } + + add_header 'Access-Control-Allow-Origin' 'http://localhost:3000' always; + add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS, PATCH, DELETE' always; + add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range' always; + add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range' always; + add_header 'Access-Control-Allow-Credentials' 'true' always; + + # Adjust these settings based on your application's needs + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + proxy_cache_bypass $http_upgrade; + + # Set the rate limit + limit_req zone=api_limit burst=20; + limit_req_status 429; + + # Forward requests to the application container (change 127.0.0.1 to your API container name if different) + proxy_pass http://api:8080; + } } From dbd34d06a32edc596ca42c8f7b341193f2ca1c34 Mon Sep 17 00:00:00 2001 From: DanglingDynamo Date: Mon, 13 May 2024 00:18:03 +0530 Subject: [PATCH 02/10] feat: README --- README.md | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/README.md b/README.md index e69de29..86f4176 100644 --- a/README.md +++ b/README.md @@ -0,0 +1,28 @@ +# Devsoc Backend '24 + +The official Backend API for DEVSOC'24 Hackathon Portal + +## Features + +- User Authentication +- Teams and Projects +- Admin panel where Admins can directly score teams + +# How To Run + +To run the backend + +## Prerequisites: + +- [Docker](https://www.docker.com): A container platform using which we can ensure standards. +- [Postman](https://www.postman.com)/[Apidog](https://apidog.com): A tool to test backend APIs without having to write frontends. +- [goose](https://github.com/pressly/goose): Goose is a database migration tool. Manage your database schema by creating incremental SQL changes or Go functions. + +## Steps + +1. Clone the Repository: `git clone https://github.com/CodeChefVIT/devsoc-backend-24` +2. Start the containers: `cd devsoc-backend-24 && cp .env.example .env && make build` Please ensure that you put the correct SMTP credentials to get email services +3. Run the migrations: `make migrate-up` +4. Use postman and test the api at the endpoint `http://localhost/api` + +# Contributors From e9099a9e8ccbf167443c7718cf1053984f9d3561 Mon Sep 17 00:00:00 2001 From: DanglingDynamo Date: Mon, 13 May 2024 00:30:20 +0530 Subject: [PATCH 03/10] feat: LICENSE --- LICENSE | 21 +++++++++++++++++++++ README.md | 2 -- 2 files changed, 21 insertions(+), 2 deletions(-) create mode 100644 LICENSE diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..0b2fe8a --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2024 CodeChef-VIT + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README.md b/README.md index 86f4176..60fefff 100644 --- a/README.md +++ b/README.md @@ -10,8 +10,6 @@ The official Backend API for DEVSOC'24 Hackathon Portal # How To Run -To run the backend - ## Prerequisites: - [Docker](https://www.docker.com): A container platform using which we can ensure standards. From f43891982889d3c376d53daffff523eb9ab60d68 Mon Sep 17 00:00:00 2001 From: DanglingDynamo Date: Mon, 13 May 2024 00:32:46 +0530 Subject: [PATCH 04/10] feat: kya bolti public --- README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.md b/README.md index 60fefff..69c9c52 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,7 @@ +

Codechef-VIT +

+
+ # Devsoc Backend '24 The official Backend API for DEVSOC'24 Hackathon Portal From d3f1c3642345e9cb9ce284a2bc1318c7b7c8eb73 Mon Sep 17 00:00:00 2001 From: DanglingDynamo Date: Mon, 13 May 2024 00:59:59 +0530 Subject: [PATCH 05/10] bade tej ho rhe --- README.md | 134 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 134 insertions(+) diff --git a/README.md b/README.md index 69c9c52..f8998de 100644 --- a/README.md +++ b/README.md @@ -28,3 +28,137 @@ The official Backend API for DEVSOC'24 Hackathon Portal 4. Use postman and test the api at the endpoint `http://localhost/api` # Contributors + + + + + + + + + + + + + + + + + + + + +
+

+ Vedant +

+

Vedant Matanhelia

+

+ GitHub + + LinkedIn + +

+
+

+ Aman +

+

Aman L

+

+ GitHub + + LinkedIn + +

+
+

+ Shivam +

+

Shivam Sharma

+

+ GitHub + + LinkedIn + +

+
+

+ Aaditya +

+

Aaditya Mahanta

+

+ GitHub + + LinkedIn + +

+
+

+ Akshat +

+

Akshat Gupta

+

+ GitHub + + LinkedIn + +

+
+

+ Prateek +

+

Prateek Srivastava

+

+ GitHub + + LinkedIn + +

+
+

+ Shivam +

+

Shivam Gutgutia

+

+ GitHub + + LinkedIn + +

+
+ +# License + +[![License](http://img.shields.io/:license-mit-blue.svg?style=flat-square)](http://badges.mit-license.org) + +

+Made with :heart: by CodeChef-VIT +

From 043982700d69aa6eb2f08b700e7495f2a865b9f3 Mon Sep 17 00:00:00 2001 From: DanglingDynamo Date: Mon, 13 May 2024 00:59:59 +0530 Subject: [PATCH 06/10] bade tej ho rhe --- README.md | 134 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 134 insertions(+) diff --git a/README.md b/README.md index 69c9c52..5e66c71 100644 --- a/README.md +++ b/README.md @@ -28,3 +28,137 @@ The official Backend API for DEVSOC'24 Hackathon Portal 4. Use postman and test the api at the endpoint `http://localhost/api` # Contributors + + + + + + + + + + + + + + + + + + + + +
+

+Vedant +

+

Vedant Matanhelia

+

+GitHub + +LinkedIn + +

+
+

+Aman +

+

Aman L

+

+GitHub + +LinkedIn + +

+
+

+Shivam +

+

Shivam Sharma

+

+GitHub + +LinkedIn + +

+
+

+Aaditya +

+

Aaditya Mahanta

+

+GitHub + +LinkedIn + +

+
+

+Akshat +

+

Akshat Gupta

+

+GitHub + +LinkedIn + +

+
+

+Prateek +

+

Prateek Srivastava

+

+GitHub + +LinkedIn + +

+
+

+Shivam +

+

Shivam Gutgutia

+

+GitHub + +LinkedIn + +

+
+ +# License + +[![License](http://img.shields.io/:license-mit-blue.svg?style=flat-square)](http://badges.mit-license.org) + +

+Made with :heart: by CodeChef-VIT +

From 55026b3a2e876a4f2150eaa5347b7f7e2b935bed Mon Sep 17 00:00:00 2001 From: DanglingDynamo Date: Mon, 13 May 2024 01:05:42 +0530 Subject: [PATCH 07/10] feat: rows --- README.md | 37 +++++++++++++++++++------------------ 1 file changed, 19 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index af68801..a0b0eb1 100644 --- a/README.md +++ b/README.md @@ -67,51 +67,52 @@ width="36" height="36" alt="LinkedIn" />

-Shivam

-

Shivam Sharma

+

Prateek Srivastava

-GitHub - + LinkedIn

- -

-Aaditya

-

Aaditya Mahanta

+

Akshat Gupta

-GitHub - + LinkedIn

+ + +

-Akshat

-

Akshat Gupta

+

Shivam Sharma

-GitHub - + LinkedIn @@ -120,15 +121,15 @@ width="36" height="36" alt="LinkedIn" />

-Prateek

-

Prateek Srivastava

+

Aaditya Mahanta

-GitHub - + LinkedIn From 2e6ccdae606ee765ec144a7e2a1e74709dc79952 Mon Sep 17 00:00:00 2001 From: DanglingDynamo Date: Mon, 13 May 2024 01:13:36 +0530 Subject: [PATCH 08/10] feat: bhai alas --- README.md | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index a0b0eb1..e9f1725 100644 --- a/README.md +++ b/README.md @@ -6,24 +6,38 @@ The official Backend API for DEVSOC'24 Hackathon Portal +## Tech Stack + +- [Golang](https://go.dev): Docker is a platform for developing, shipping, and running applications using containers. + + - [Echo](https://echo.labstack.com/): A fast http router based on the go standard HTTP. + - [pgx](https://github.com/jackc/pgx): A postgresql driver for go. + - [gomail](https://github.com/go-gomail/gomail): A library to send emails using go. + - [go-redis](https://github.com/redis/go-redis): Go redis client. + +- [Docker](https://www.docker.com): Docker is a platform for developing, shipping, and running applications using containers. +- [PostgreSQL](https://www.postgresql.org/): The worlds most advanced Open Source Relational Database. +- [Redis](https://redis.io): The world’s fastest in-memory database from the ones who built it. + ## Features - User Authentication -- Teams and Projects -- Admin panel where Admins can directly score teams +- Teams +- Project management +- Admin routes where Admins can directly score teams # How To Run ## Prerequisites: -- [Docker](https://www.docker.com): A container platform using which we can ensure standards. +- [Docker](https://www.docker.com): . - [Postman](https://www.postman.com)/[Apidog](https://apidog.com): A tool to test backend APIs without having to write frontends. - [goose](https://github.com/pressly/goose): Goose is a database migration tool. Manage your database schema by creating incremental SQL changes or Go functions. ## Steps 1. Clone the Repository: `git clone https://github.com/CodeChefVIT/devsoc-backend-24` -2. Start the containers: `cd devsoc-backend-24 && cp .env.example .env && make build` Please ensure that you put the correct SMTP credentials to get email services +2. Start the containers: `cd devsoc-backend-24 && cp .env.example .env && make build`. Please ensure that you put the correct SMTP credentials to get email services 3. Run the migrations: `make migrate-up` 4. Use postman and test the api at the endpoint `http://localhost/api` From 1ac91d29247bb9296154d4c52de918fb1b27822b Mon Sep 17 00:00:00 2001 From: DanglingDynamo Date: Mon, 13 May 2024 01:16:25 +0530 Subject: [PATCH 09/10] feat: Update LICENSE --- LICENSE | 2 +- README.md | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/LICENSE b/LICENSE index 0b2fe8a..8f92967 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2024 CodeChef-VIT +Copyright (c) 2024 CodeChef-VIT and All other contributors Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/README.md b/README.md index e9f1725..d5e1154 100644 --- a/README.md +++ b/README.md @@ -171,7 +171,8 @@ width="36" height="36" alt="LinkedIn" /> # License -[![License](http://img.shields.io/:license-mit-blue.svg?style=flat-square)](http://badges.mit-license.org) +Copyright © 2024, [CodeChef-VIT](https://github.com/CodeChefVIT) and all other contributors. +Released under the [MIT License](LICENSE).

Made with :heart: by CodeChef-VIT From 2c886f3b8f80f8eed53160ac450364eefa34290b Mon Sep 17 00:00:00 2001 From: DanglingDynamo Date: Mon, 13 May 2024 01:17:24 +0530 Subject: [PATCH 10/10] feat: README --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index d5e1154..06bfe8d 100644 --- a/README.md +++ b/README.md @@ -41,7 +41,7 @@ The official Backend API for DEVSOC'24 Hackathon Portal 3. Run the migrations: `make migrate-up` 4. Use postman and test the api at the endpoint `http://localhost/api` -# Contributors +# Authors