Skip to content

Commit 8e85ae9

Browse files
authored
Merge pull request #167 from CS3219-AY2425S1/enhancement/api-gateway
Add API gateway
2 parents 01f9344 + dda9217 commit 8e85ae9

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+425
-133
lines changed

.env.sample

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ FRONTEND_PORT=3000
99
BASE_URI=
1010

1111
## Question service variables
12-
QUESTION_SVC_PORT=
12+
QUESTION_SVC_PORT=8000
1313
QUESTION_SVC_DB_URI=
1414

1515
## User service variables
16-
USER_SVC_PORT=
16+
USER_SVC_PORT=3001
1717
USER_SVC_DB_URI=
1818
JWT_SECRET=
1919
EMAIL_ADDRESS=
@@ -31,4 +31,7 @@ OPENAI_API_KEY=
3131
REDIS_PORT=6379
3232

3333
## Redisinsight variables
34-
REDIS_INSIGHT_PORT=5540
34+
REDIS_INSIGHT_PORT=5540
35+
36+
## API Gateway variables
37+
API_GATEWAY_PORT=

api-gateway/nginx.conf

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
user nginx;
2+
worker_processes auto;
3+
4+
error_log /var/log/nginx/error.log notice;
5+
pid /var/run/nginx.pid;
6+
7+
8+
events {
9+
worker_connections 1024;
10+
}
11+
12+
13+
http {
14+
include /etc/nginx/mime.types;
15+
default_type application/octet-stream;
16+
17+
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
18+
'$status $body_bytes_sent "$http_referer" '
19+
'"$http_user_agent" "$http_x_forwarded_for"';
20+
21+
access_log /var/log/nginx/access.log main;
22+
23+
sendfile on;
24+
#tcp_nopush on;
25+
26+
keepalive_timeout 65;
27+
28+
#gzip on;
29+
30+
map $http_upgrade $connection_upgrade {
31+
default upgrade;
32+
'' close;
33+
}
34+
35+
include /etc/nginx/conf.d/*.conf;
36+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
location /admin/matching-service/ {
2+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
location /admin/question-service/ {
2+
location /admin/question-service/questions {
3+
proxy_pass http://question-service/questions;
4+
}
5+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
upstream user-service {
2+
server user-service:$USER_SVC_PORT;
3+
}
4+
5+
upstream question-service {
6+
server question-service:$QUESTION_SVC_PORT;
7+
}
8+
9+
upstream matching-service {
10+
server matching-service:$MATCHING_SVC_PORT;
11+
}
12+
13+
upstream collab-service {
14+
server collab-service:$COLLAB_SVC_PORT;
15+
}
16+
17+
upstream frontend {
18+
server frontend:$FRONTEND_PORT;
19+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
location /verify-token {
2+
internal;
3+
4+
proxy_pass_request_body off;
5+
proxy_set_header Content-Length "";
6+
proxy_pass http://user-service/auth/verify-token;
7+
}
8+
9+
location /verify-owner {
10+
internal;
11+
12+
proxy_pass_request_body off;
13+
proxy_set_header Content-Length "";
14+
proxy_pass http://user-service/auth/verify-owner;
15+
}
16+
17+
location /verify-admin {
18+
internal;
19+
20+
proxy_pass_request_body off;
21+
proxy_set_header Content-Length "";
22+
proxy_pass http://user-service/auth/verify-admin;
23+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
location / {
2+
proxy_pass http://frontend;
3+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
location /owner/matching-service/ {
2+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
location /owner/question-service/ {
2+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
location /private/collab-service/ {
2+
proxy_pass http://collab-service/;
3+
proxy_http_version 1.1;
4+
proxy_set_header Upgrade $http_upgrade;
5+
proxy_set_header Connection $connection_upgrade;
6+
proxy_set_header Host $host;
7+
proxy_set_header X-Real-IP $remote_addr;
8+
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
9+
proxy_set_header X-Forwarded-Proto $scheme;
10+
}

0 commit comments

Comments
 (0)