Skip to content

Commit 4dc737d

Browse files
committed
Add second gateway to connect socket.io behind
1 parent 2838af0 commit 4dc737d

File tree

8 files changed

+89
-7
lines changed

8 files changed

+89
-7
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: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -151,16 +151,25 @@ services:
151151
nginx:
152152
build: nginx
153153
image: distractedcat/nginx
154-
ports:
155-
- "80:80"
156154
volumes:
157-
- ./nginx/nginx.conf:/etc/nginx/nginx.conf
155+
- ./nginx/nginx.conf:/etc/nginx/internal.conf
158156
depends_on:
159157
- peerprep
160158
- backend
161159
- user-service
162160
- storage-blob-api
163161
- matching-service-api
162+
163+
inbound-gateway:
164+
build: inbound-gateway
165+
image: wzwren/inbound-gateway
166+
ports:
167+
- "70:70"
168+
volumes:
169+
- ./inbound-gateway/nginx.conf:/etc/nginx/external.conf
170+
depends_on:
171+
- peerprep
172+
- comms
164173
# mongo:
165174
# image: "mongo:latest"
166175
# 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 70
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 70;
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:70;
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: 2 additions & 2 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
2+
COPY nginx.conf /etc/nginx/internal.conf
33
EXPOSE 80
4-
CMD ["nginx", "-g", "daemon off;"]
4+
CMD ["nginx", "-c", "internal.conf", "-g", "daemon off;"]

nginx/nginx.conf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ http {
5959
proxy_http_version 1.1;
6060
proxy_set_header Upgrade $http_upgrade;
6161
proxy_set_header Connection "upgrade";
62+
proxy_read_timeout 86400;
6263
}
6364

6465
location /users/ {

peerprep/components/questionpage/CommsPanel.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ interface Props {
77
roomId?: String;
88
}
99

10-
const socket = io(`${process.env.NEXT_PUBLIC_COMMS}`);
10+
const socket = io(`/`, {
11+
path: '/comms'
12+
});
1113

1214
function CommsPanel({ className, roomId }: Props) {
1315
const [stream, setStream] = useState<MediaStream>();

0 commit comments

Comments
 (0)