File tree 15 files changed +56
-18
lines changed
game-service/Game.Application
maple-fighters/Assets/Maple Fighters
ScriptableObjects/Configurations
15 files changed +56
-18
lines changed Original file line number Diff line number Diff line change @@ -7,7 +7,7 @@ services:
7
7
REACT_APP_ENV : Production
8
8
REMOVE_CF_IPS : " false"
9
9
ports :
10
- - 80:80
10
+ - 443:443
11
11
depends_on :
12
12
- game-service
13
13
game-service :
@@ -16,7 +16,7 @@ services:
16
16
expose :
17
17
- 50051
18
18
environment :
19
- URL : ws ://0.0.0.0:50051
19
+ URL : wss ://0.0.0.0:50051
20
20
FLECK_LOG : Info
21
21
IM_LOG : Debug
22
22
GAME_LOG : Debug
Original file line number Diff line number Diff line change @@ -10,7 +10,7 @@ services:
10
10
REACT_APP_ENV : Development
11
11
REMOVE_CF_IPS : " true"
12
12
ports :
13
- - 80:80
13
+ - 443:443
14
14
depends_on :
15
15
- game-service
16
16
game-service :
@@ -21,7 +21,7 @@ services:
21
21
expose :
22
22
- 50051
23
23
environment :
24
- URL : ws ://0.0.0.0:50051
24
+ URL : wss ://0.0.0.0:50051
25
25
FLECK_LOG : Info
26
26
IM_LOG : Debug
27
27
GAME_LOG : Debug
Original file line number Diff line number Diff line change 18
18
image : maplefighters/frontend:2.0.0
19
19
imagePullPolicy : Always
20
20
ports :
21
- - containerPort : 80
21
+ - containerPort : 443
22
22
env :
23
23
- name : REACT_APP_ENV
24
24
value : " Development"
@@ -45,8 +45,8 @@ metadata:
45
45
spec :
46
46
type : LoadBalancer
47
47
ports :
48
- - name : http
49
- port : 80
50
- targetPort : 80
48
+ - name : https
49
+ port : 443
50
+ targetPort : 443
51
51
selector :
52
52
app : frontend
Original file line number Diff line number Diff line change 31
31
- name : IM_LOG
32
32
value : Debug
33
33
- name : URL
34
- value : ws ://0.0.0.0:50051
34
+ value : wss ://0.0.0.0:50051
35
35
resources :
36
36
requests :
37
37
cpu : 100m
Original file line number Diff line number Diff line change @@ -7,6 +7,8 @@ RUN npm run build
7
7
8
8
FROM nginx:1.20.1-alpine
9
9
COPY --from=builder /app/nginx.conf /etc/nginx/nginx.conf
10
+ COPY --from=builder /app/server.crt /etc/nginx/ssl/server.crt
11
+ COPY --from=builder /app/server.key /etc/nginx/ssl/server.key
10
12
COPY --from=builder /app/cloudflare-ips.conf /var/www-allow/cloudflare-ips.conf
11
13
COPY --from=builder /app/build /usr/share/nginx/html
12
14
COPY --from=builder /app/entrypoint.sh /entrypoint.sh
Original file line number Diff line number Diff line change @@ -16,10 +16,24 @@ http {
16
16
server game-service:50051;
17
17
}
18
18
19
- server {
19
+ server {
20
20
listen 80 ;
21
21
server_name _;
22
22
23
+ # Redirect all HTTP requests to HTTPS
24
+ return 301 https://$host$request_uri ;
25
+ }
26
+
27
+ server {
28
+ listen 443 ssl;
29
+ server_name _;
30
+
31
+ # SSL configuration
32
+ ssl_certificate /etc/nginx/ssl/server.crt;
33
+ ssl_certificate_key /etc/nginx/ssl/server.key;
34
+ ssl_protocols TLSv1.2 TLSv1.3;
35
+ ssl_ciphers HIGH:!aNULL:!MD5;
36
+
23
37
limit_req zone=req burst=10 delay=5;
24
38
limit_req_status 444;
25
39
limit_rate 5m ;
31
45
}
32
46
33
47
location /game {
34
- # Source: https://github.com/nicokaiser/nginx-websocket-proxy/blob/master/simple-ws.conf
35
- # redirect all HTTP traffic to game-service
36
- proxy_pass http://game/;
48
+ # Upgrade to WebSocket protocol over HTTPS
49
+ proxy_pass https://game/;
37
50
proxy_set_header X-Real-IP $remote_addr ;
38
51
proxy_set_header Host $host ;
39
52
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for ;
Original file line number Diff line number Diff line change 1
- URL = ws ://0.0.0.0:50051
1
+ URL = wss ://0.0.0.0:50051
2
2
FLECK_LOG = Info
3
3
IM_LOG = Debug
4
4
GAME_LOG = Debug
Original file line number Diff line number Diff line change @@ -8,4 +8,5 @@ RUN dotnet publish -c release -o /app --no-restore
8
8
FROM mcr.microsoft.com/dotnet/runtime:5.0
9
9
WORKDIR /app
10
10
COPY --from=builder /app .
11
+ COPY --from=builder /source/server.crt .
11
12
ENTRYPOINT ["dotnet" , "Game.Application.dll" ]
Original file line number Diff line number Diff line change 1
1
using System ;
2
+ using System . Security . Cryptography . X509Certificates ;
2
3
using DotNetEnv ;
3
4
using Fleck ;
4
5
using Game . Application ;
24
25
25
26
var url = Env . GetString ( "URL" ) ;
26
27
var server = new WebSocketServer ( url ) ;
28
+ server . Certificate = new X509Certificate2 ( "server.crt" ) ;
27
29
var serverComponents = new ComponentCollection ( new IComponent [ ]
28
30
{
29
31
new IdGenerator ( ) ,
Original file line number Diff line number Diff line change 2
2
docker build -t game-service .
3
3
4
4
run :
5
- docker run -p 50051:50051 game-service -e URL=ws://0.0.0.0:50051 \
5
+ docker run -p 50051:50051 game-service -e \
6
+ URL=wss://0.0.0.0:50051 \
6
7
FLECK_LOG=Info \
7
8
IM_LOG=Debug \
8
- GAME_LOG=Debug
9
+ GAME_LOG=Debug \
10
+ CONFIG_SOURCE=v2.0 \
11
+ MAX_CONNECTIONS=100
Original file line number Diff line number Diff line change @@ -43,4 +43,4 @@ make build
43
43
make run
44
44
```
45
45
46
- You should now be able to access it at ` ws ://localhost:50051` .
46
+ You should now be able to access it at ` wss ://localhost:50051` .
Original file line number Diff line number Diff line change @@ -14,12 +14,15 @@ MonoBehaviour:
14
14
m_EditorClassIdentifier :
15
15
HostingData :
16
16
- Name : Editor
17
+ Protocol : ws
17
18
Host : localhost
18
19
Environment : 0
19
20
- Name : Development
21
+ Protocol : ws
20
22
Host : localhost
21
23
Environment : 1
22
24
- Name : Production
25
+ Protocol : wss
23
26
Host : maplefighters.io
24
27
Environment : 2
25
28
Environment : 0
Original file line number Diff line number Diff line change @@ -7,6 +7,8 @@ public class HostingData
7
7
{
8
8
public string Name ;
9
9
10
+ public string Protocol ;
11
+
10
12
public string Host ;
11
13
12
14
public HostingEnvironment Environment ;
Original file line number Diff line number Diff line change @@ -14,6 +14,18 @@ public class NetworkConfiguration : ScriptableSingleton<NetworkConfiguration>
14
14
15
15
public HostingEnvironment Environment ;
16
16
17
+ public string GetProtocol ( )
18
+ {
19
+ var hostingData =
20
+ HostingData . FirstOrDefault ( ( x ) => x . Environment == Environment ) ;
21
+ if ( hostingData != null )
22
+ {
23
+ return hostingData . Protocol ;
24
+ }
25
+
26
+ return string . Empty ;
27
+ }
28
+
17
29
public string GetHost ( )
18
30
{
19
31
var hostingData =
Original file line number Diff line number Diff line change @@ -77,7 +77,7 @@ private void Start()
77
77
78
78
var uriBuilder = new UriBuilder ( )
79
79
{
80
- Scheme = "ws" ,
80
+ Scheme = networkConfiguration . GetProtocol ( ) ,
81
81
Host = networkConfiguration . GetHost ( ) ,
82
82
Path = "game"
83
83
} ;
You can’t perform that action at this time.
0 commit comments