Skip to content

Commit 476955f

Browse files
Merge pull request #78 from upayanmazumder-DevLabs/master
oauth
2 parents a56ca0a + 4613fd8 commit 476955f

13 files changed

Lines changed: 438 additions & 216 deletions

File tree

.air.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,4 @@ tmp_dir = "tmp"
2323

2424
[misc]
2525
clean_on_exit = true
26+

.env.example

Lines changed: 15 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,69 +1,41 @@
11
PORT=8080
2-
JWT_SECRET=
3-
2+
JWT_SECRET=devsoc_secret
43
FRONTEND_URL=http://localhost:3000
54

65
POSTGRES_HOST=postgres
76
POSTGRES_PORT=5432
8-
POSTGRES_USER=devsoc
7+
POSTGRES_USER=
98
POSTGRES_PASSWORD=devsoc
109
POSTGRES_DB=devsoc
1110

12-
REDIS_HOST=
13-
REDIS_PORT=
14-
REDIS_PASSWORD=
15-
16-
SECURE=false
11+
REDIS_HOST=redis
12+
REDIS_PORT=6379
13+
REDIS_PASSWORD=devsoc
1714

15+
# Elastic Search
1816
ELASTIC_HOST=elasticsearch
1917
ELASTIC_PORT=9200
2018
ELASTIC_SCHEME=http
2119
ELASTIC_USERNAME=elastic
2220
ELASTIC_PASSWORD=gyattpass
2321
ELASTIC_INDEX=logs
24-
logger.level=ERROR #otherwise elastic search will keep yapping - i couldn't read shit b4 -- set to WARN if you wanna read sm not so imp stuff
25-
discovery.type=single-node #idk but sm sort of bootstrap issue
22+
logger.level=ERROR
23+
discovery.type=single-node
2624

2725
xpack.security.enabled=false
28-
2926
bootstrap.memory_lock=true
30-
ES_JAVA_OPTS=-Xms2g -Xmx2g #this is 4 sm memory related issues that might occur in docker fk elasticsearch
27+
ES_JAVA_OPTS=-Xms256m -Xmx256m #this is 4 sm memory related issues that might occur in docker fk elasticsearch
3128
# ts stands for -initial -max (heap sizes) and 2g signifies 2GB idk how much we'll actually need for logs but jus change that part as req ig
3229

33-
ENV=
30+
ENV=development
3431

3532
GOOSE_MIGRATION_DIR=database/schema
3633
GOOSE_DRIVER=postgres
3734
GOOSE_DBSTRING=postgres://devsoc:devsoc@postgres:5432/devsoc?sslmode=disable
3835

39-
SMTP_ACCOUNTS=6
40-
41-
SMTP_0_HOST=
42-
SMTP_0_PORT=
43-
SMTP_0_USER=
44-
SMTP_0_PASS=
45-
46-
SMTP_1_HOST=
47-
SMTP_1_PORT=
48-
SMTP_1_USER=
49-
SMTP_1_PASS=
50-
51-
SMTP_2_HOST=
52-
SMTP_2_PORT=
53-
SMTP_2_USER=
54-
SMTP_2_PASS=
55-
56-
SMTP_3_HOST=
57-
SMTP_3_PORT=
58-
SMTP_3_USER=
59-
SMTP_3_PASS=
60-
61-
SMTP_4_HOST=
62-
SMTP_4_PORT=
63-
SMTP_4_USER=
64-
SMTP_4_PASS=
36+
# NextAuth.js secret for signing and encrypting session tokens
37+
NEXTAUTH_SECRET=
6538

66-
SMTP_5_HOST=
67-
SMTP_5_PORT=
68-
SMTP_5_USER=
69-
SMTP_5_PASS=
39+
# Google OAuth credentials
40+
GOOGLE_CLIENT_ID=
41+
GOOGLE_CLIENT_SECRET=

Dockerfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ WORKDIR /app
88
RUN go install github.com/air-verse/air@latest
99
RUN go install github.com/pressly/goose/v3/cmd/goose@latest
1010

11+
ENV PATH="/go/bin:${PATH}"
12+
1113
COPY go.mod go.sum ./
1214

1315
RUN go mod download

Dockerfile.dev

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
FROM golang:1.25-alpine
2+
3+
RUN apk add --no-cache git
4+
5+
WORKDIR /app
6+
7+
# install air
8+
RUN go install github.com/air-verse/air@latest
9+
RUN go install github.com/pressly/goose/v3/cmd/goose@latest
10+
11+
ENV PATH="/go/bin:${PATH}"
12+
13+
COPY go.mod go.sum ./
14+
RUN go mod download
15+
16+
COPY . .
17+
18+
EXPOSE 8080
19+
20+
CMD ["air", "-c", ".air.toml"]

cmd/api/main.go

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"context"
55
"log"
66
"net/http"
7-
"os"
87

98
"github.com/CodeChefVIT/devsoc-backend-26/pkg/elastic"
109
"github.com/CodeChefVIT/devsoc-backend-26/pkg/middlewares"
@@ -48,17 +47,20 @@ func main() {
4847

4948
e := echo.New()
5049

51-
// Enable CORS only in development mode
52-
if os.Getenv("ENV") == "development" {
50+
// Enable CORS when FRONTEND_URL is configured. Allow credentials and
51+
// respond to preflight requests. Must echo exact origin (not '*') so
52+
// browsers will accept credentials for cross-site cookies.
53+
allowedOrigin := utils.Config.FrontendURL
54+
if allowedOrigin != "" {
5355
e.Use(func(next echo.HandlerFunc) echo.HandlerFunc {
5456
return func(c echo.Context) error {
5557
origin := c.Request().Header.Get("Origin")
56-
allowedOrigin := os.Getenv("FRONTEND_URL")
5758
if origin == allowedOrigin {
58-
c.Response().Header().Set("Access-Control-Allow-Origin", allowedOrigin)
59-
c.Response().Header().Set("Access-Control-Allow-Methods", "GET,POST,PUT,PATCH,DELETE,OPTIONS")
60-
c.Response().Header().Set("Access-Control-Allow-Headers", "Content-Type, Authorization")
61-
c.Response().Header().Set("Access-Control-Allow-Credentials", "true")
59+
hdr := c.Response().Header()
60+
hdr.Set("Access-Control-Allow-Origin", allowedOrigin)
61+
hdr.Set("Access-Control-Allow-Methods", "GET,POST,PUT,PATCH,DELETE,OPTIONS")
62+
hdr.Set("Access-Control-Allow-Headers", "Content-Type, Authorization, X-Requested-With")
63+
hdr.Set("Access-Control-Allow-Credentials", "true")
6264
if c.Request().Method == "OPTIONS" {
6365
return c.NoContent(http.StatusNoContent)
6466
}
@@ -77,7 +79,7 @@ func main() {
7779
e.Use(middlewares.RequestLogger)
7880
router.RegisterRoute(e)
7981

80-
port := os.Getenv("PORT")
82+
port := utils.Config.Port
8183
if port == "" {
8284
port = "8080"
8385
}

docker-compose.dev.yaml

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
services:
2+
elasticsearch:
3+
image: docker.elastic.co/elasticsearch/elasticsearch:9.2.3
4+
container_name: elastic
5+
env_file:
6+
- .env
7+
ports:
8+
- 127.0.0.1:9200:9200
9+
volumes:
10+
- ./elasticsearch/certs:/usr/share/elasticsearch/config/certs:ro
11+
- elastic_data:/usr/share/elasticsearch/data
12+
ulimits:
13+
memlock:
14+
soft: -1
15+
hard: -1
16+
nofile:
17+
soft: 65536
18+
hard: 65536
19+
healthcheck:
20+
test:
21+
["CMD-SHELL", "curl http://localhost:9200/_cluster/health || exit 1"]
22+
interval: 5s
23+
timeout: 2s
24+
retries: 20
25+
26+
postgres:
27+
image: postgres:16
28+
container_name: devsoc_postgres
29+
env_file:
30+
- .env
31+
ports:
32+
- "127.0.0.1:5432:5432"
33+
volumes:
34+
- postgres_data:/var/lib/postgresql/data
35+
36+
redis:
37+
image: redis:latest
38+
container_name: devsoc_redis
39+
ports:
40+
- "127.0.0.1:6379:6379"
41+
env_file:
42+
- .env
43+
volumes:
44+
- redis_data:/data
45+
46+
api:
47+
build:
48+
context: ./
49+
dockerfile: Dockerfile.dev
50+
container_name: devsoc_api
51+
ports:
52+
- "127.0.0.1:8080:8080"
53+
volumes:
54+
- .:/app
55+
env_file:
56+
- .env
57+
environment:
58+
- GOFLAGS=-buildvcs=false
59+
restart: on-failure
60+
depends_on:
61+
elasticsearch:
62+
condition: service_healthy
63+
postgres:
64+
condition: service_started
65+
redis:
66+
condition: service_started
67+
command: >
68+
sh -c "
69+
goose -dir database/schema up &&
70+
air -c .air.toml
71+
"
72+
73+
volumes:
74+
postgres_data:
75+
redis_data:
76+
elastic_data:

go.mod

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ require (
2525
github.com/go-logr/stdr v1.2.2 // indirect
2626
github.com/go-playground/locales v0.14.1 // indirect
2727
github.com/go-playground/universal-translator v0.18.1 // indirect
28-
github.com/gocarina/gocsv v0.0.0-20240520201108-78e41c74b4b1 // indirect
2928
github.com/goccy/go-json v0.10.3 // indirect
3029
github.com/jackc/pgpassfile v1.0.0 // indirect
3130
github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 // indirect

go.sum

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,6 @@ github.com/go-playground/universal-translator v0.18.1 h1:Bcnm0ZwsGyWbCzImXv+pAJn
3434
github.com/go-playground/universal-translator v0.18.1/go.mod h1:xekY+UJKNuX9WP91TpwSH2VMlDf28Uj24BCp08ZFTUY=
3535
github.com/go-playground/validator/v10 v10.30.0 h1:5YBPNs273uzsZJD1I8uiB4Aqg9sN6sMDVX3s6LxmhWU=
3636
github.com/go-playground/validator/v10 v10.30.0/go.mod h1:oSuBIQzuJxL//3MelwSLD5hc2Tu889bF0Idm9Dg26cM=
37-
github.com/gocarina/gocsv v0.0.0-20240520201108-78e41c74b4b1 h1:FWNFq4fM1wPfcK40yHE5UO3RUdSNPaBC+j3PokzA6OQ=
38-
github.com/gocarina/gocsv v0.0.0-20240520201108-78e41c74b4b1/go.mod h1:5YoVOkjYAQumqlV356Hj3xeYh4BdZuLE0/nRkf2NKkI=
3937
github.com/goccy/go-json v0.10.3 h1:KZ5WoDbxAIgm2HNbYckL0se1fHD6rz5j4ywS6ebzDqA=
4038
github.com/goccy/go-json v0.10.3/go.mod h1:oq7eo15ShAhp70Anwd5lgX2pLfOS3QCiwU/PULtXL6M=
4139
github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8=

0 commit comments

Comments
 (0)