aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--api/game/socket.py2
-rw-r--r--nginx.conf18
-rw-r--r--pages/game.tsx21
3 files changed, 24 insertions, 17 deletions
diff --git a/api/game/socket.py b/api/game/socket.py
index d6dff1b..fdeac73 100644
--- a/api/game/socket.py
+++ b/api/game/socket.py
@@ -19,7 +19,7 @@ class game:
self.board.drop_fisje(column)
def run(app):
- io = SocketIO(app)
+ io = SocketIO(app, cors_allowed_origins="*")
@io.on("new_move", namespace)
def new_move(data):
diff --git a/nginx.conf b/nginx.conf
index 403bfe8..f94cba2 100644
--- a/nginx.conf
+++ b/nginx.conf
@@ -5,24 +5,30 @@ events {}
http {
server {
- listen 2080 default_server;
+ listen 2080 default;
server_name localhost;
location / {
- proxy_pass http://localhost:3000;
+ proxy_pass http://127.0.0.1:3000;
}
location /api {
- proxy_pass http://localhost:5000/;
+ proxy_pass http://127.0.0.1:5000/;
}
location /socket.io {
- # include proxy_params;
- proxy_http_version 1.1;
+ proxy_pass http://127.0.0.1:5000/socket.io;
+
+ proxy_redirect off;
proxy_buffering off;
+
+ proxy_set_header Host $host;
+ proxy_set_header X-Real-IP $remote_addr;
+ proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
+
+ proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "Upgrade";
- proxy_pass http://localhost:5000/socket.io;
}
}
}
diff --git a/pages/game.tsx b/pages/game.tsx
index 1c66f92..8728674 100644
--- a/pages/game.tsx
+++ b/pages/game.tsx
@@ -1,17 +1,10 @@
import { CSSProperties, Component } from 'react';
-import { io } from 'socket.io-client';
+import { io as socket } from 'socket.io-client';
import axios from 'axios';
import { userInfo } from '../api/api';
import * as cookies from 'react-cookies';
-var socket = io("http://localhost:2080/api/game/socket/");
-
-socket.on("connect", () => {
- console.log("connect")
-})
-socket.on("disconnect", () => {
- console.log("disconnect")
-})
+var io = socket("http://localhost:2080/api/game/socket/");
import { NavBar } from '../components/navbar';
import { CenteredPage } from '../components/page';
@@ -57,6 +50,14 @@ interface VoerGameProps {
class VoerGame extends Component<VoerGameProps> {
constructor(props: VoerGameProps) {
super(props);
+
+ io.on("connect", () => {
+ console.log("connect")
+ io.emit("resign", {"cool": "data"});
+ })
+ io.on("disconnect", () => {
+ console.log("disconnect")
+ })
}
width = 7;
@@ -87,7 +88,7 @@ class VoerGame extends Component<VoerGameProps> {
token: cookies.load("token"),
gameID: "fortnite"
})
- socket.emit("new_move", {
+ io.emit("new_move", {
move: column,
token: cookies.load("token"),
gameID: "fortnite"