Skip to content

Commit fde213a

Browse files
authored
Merge pull request #64 from CS3219-AY2425S1/second-nginx
Add 2nd gateway and integrate with frontend changes
2 parents 9c75fcd + 587ebe4 commit fde213a

File tree

14 files changed

+105
-25
lines changed

14 files changed

+105
-25
lines changed

comms/server.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
const express = require("express");
22
const http = require("http");
33
const app = express();
4+
45
const server = http.createServer(app);
56
const io = require("socket.io")(server, {
7+
path: '/comms',
68
cors: {
79
// temporarily use * to allow all origins
8-
origin: `*`
10+
origin: `*`,
11+
methods: ["GET", "POST"]
912
}
1013
});
1114

compose.yaml

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -165,16 +165,27 @@ services:
165165
nginx:
166166
build: nginx
167167
image: distractedcat/nginx
168-
ports:
169-
- "80:80"
170168
volumes:
171-
- ./nginx/nginx.conf:/etc/nginx/nginx.conf
169+
- ./nginx/nginx.conf:/etc/nginx/internal.conf
170+
ports:
171+
- "70:70"
172172
depends_on:
173173
- peerprep
174174
- backend
175175
- user-service
176176
- storage-blob-api
177177
- matching-service-api
178+
179+
inbound-gateway:
180+
build: inbound-gateway
181+
image: wzwren/inbound-gateway
182+
ports:
183+
- "80:80"
184+
volumes:
185+
- ./inbound-gateway/nginx.conf:/etc/nginx/external.conf
186+
depends_on:
187+
- peerprep
188+
- comms
178189
# mongo:
179190
# image: "mongo:latest"
180191
# ports:

inbound-gateway/Dockerfile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
FROM nginx:alpine
2+
COPY nginx.conf /etc/nginx/external.conf
3+
EXPOSE 80
4+
CMD ["nginx", "-c", "external.conf", "-g", "daemon off;"]

inbound-gateway/README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
nginx is dockerised, just have to run `docker compose up --build` as usual.
2+
3+
if edits are made to the local nginx.conf file, following command must be run to see changes reflected in docker:
4+
5+
`docker exec cs3219-ay2425s1-project-g14-nginx-1 nginx -s reload`
6+
7+
(or just exec `nginx -s reload` in the container directly)

inbound-gateway/nginx.conf

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
worker_processes 1;
2+
3+
events {
4+
worker_connections 1024;
5+
}
6+
7+
http {
8+
include mime.types;
9+
10+
default_type application/octet-stream;
11+
12+
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
13+
'$status $body_bytes_sent "$http_referer" '
14+
'"$http_user_agent" "$http_x_forwarded_for"';
15+
16+
sendfile on;
17+
#tcp_nopush on;
18+
19+
keepalive_timeout 65;
20+
21+
upstream peerprep {
22+
server peerprep:3000;
23+
}
24+
25+
server {
26+
listen 80;
27+
28+
location / {
29+
proxy_pass http://peerprep/;
30+
proxy_set_header Host $host;
31+
proxy_set_header X-Real-IP $remote_addr;
32+
proxy_set_header X-Forwarded-Proto $scheme;
33+
proxy_set_header X-Forwarded-Host $host; # port 80 implicitly removes this port
34+
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
35+
proxy_http_version 1.1;
36+
proxy_set_header Upgrade $http_upgrade;
37+
proxy_set_header Connection "upgrade";
38+
proxy_read_timeout 86400;
39+
}
40+
41+
location /comms/ {
42+
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
43+
proxy_set_header X-Real-IP $remote_addr;
44+
proxy_set_header Host $host;
45+
proxy_set_header X-NginX-Proxy false;
46+
47+
48+
proxy_pass http://comms:4001;
49+
50+
proxy_http_version 1.1;
51+
proxy_set_header Upgrade $http_upgrade;
52+
proxy_set_header Connection "upgrade";
53+
proxy_read_timeout 86400;
54+
}
55+
}
56+
}

nginx/Dockerfile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
FROM nginx:alpine
2-
COPY nginx.conf /etc/nginx/nginx.conf
3-
EXPOSE 80
4-
CMD ["nginx", "-g", "daemon off;"]
2+
COPY nginx.conf /etc/nginx/internal.conf
3+
EXPOSE 70
4+
CMD ["nginx", "-c", "internal.conf", "-g", "daemon off;"]

nginx/nginx.conf

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ http {
5353
# }
5454

5555
server {
56-
listen 80;
56+
listen 70;
5757
location / {
5858
proxy_pass http://peerprep/;
5959
proxy_set_header Host $host;
@@ -63,6 +63,7 @@ http {
6363
proxy_http_version 1.1;
6464
proxy_set_header Upgrade $http_upgrade;
6565
proxy_set_header Connection "upgrade";
66+
proxy_read_timeout 86400;
6667
}
6768

6869
location /users/ {

peerprep/app/actions/server_actions.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ export async function hydrateUid(): Promise<null | UserData> {
9595
if (isError(json)) {
9696
console.log("Failed to fetch user ID.");
9797
console.log(`Error ${json.status}: ${json.error}`);
98-
redirect("/api/internal/auth/expire");
98+
redirect("/auth/logout");
9999
}
100100
// TODO: handle error handling
101101
const response = json as UserServiceResponse;

peerprep/app/actions/session.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,3 @@ export async function createSession(userDataAccessToken: UserDataAccessToken) {
4646
console.error("Error setting cookie:", error);
4747
}
4848
}
49-
50-
export async function expireSession() {
51-
Object.values(CookieNames).forEach((name) => cookies().delete(name));
52-
}

peerprep/app/api/internal/auth/expire/route.ts

Lines changed: 0 additions & 9 deletions
This file was deleted.

0 commit comments

Comments
 (0)