diff --git a/.gitignore b/.gitignore
index 6a1037f..f68cb52 100644
--- a/.gitignore
+++ b/.gitignore
@@ -125,3 +125,7 @@ dist
npm-debug.log*
yarn-debug.log*
yarn-error.log*
+/venv
+/__pycache__
+venv
+__pycache__
\ No newline at end of file
diff --git a/.idea/Mafia.iml b/.idea/Mafia.iml
index d0876a7..8b8c395 100644
--- a/.idea/Mafia.iml
+++ b/.idea/Mafia.iml
@@ -5,4 +5,8 @@
+
+
+
+
\ No newline at end of file
diff --git a/.idea/misc.xml b/.idea/misc.xml
index a2e120d..ba24381 100644
--- a/.idea/misc.xml
+++ b/.idea/misc.xml
@@ -1,4 +1,7 @@
+
+
+
\ No newline at end of file
diff --git a/backend/lib/api.py b/backend/lib/api.py
new file mode 100644
index 0000000..a5eea58
--- /dev/null
+++ b/backend/lib/api.py
@@ -0,0 +1,6 @@
+from flask import Flask
+from lib.routes import api
+
+app = Flask(__name__)
+
+app.register_blueprint(api)
diff --git a/backend/lib/models/__init__.py b/backend/lib/models/__init__.py
new file mode 100644
index 0000000..e69de29
diff --git a/backend/lib/routes.py b/backend/lib/routes.py
new file mode 100644
index 0000000..9331628
--- /dev/null
+++ b/backend/lib/routes.py
@@ -0,0 +1,16 @@
+import time
+from random import randrange
+
+from flask import request, jsonify, Blueprint
+
+api = Blueprint('api', 'api', url_prefix='/api')
+
+
+@api.route('/room/create', methods=['POST'])
+def createRoom():
+ creator_id = request.get_json().get('creatorID')
+ room_id = randrange(999999999)
+ creation_date = time.time()
+ room_socket_port = randrange(30000, 50000)
+
+ return jsonify({'roomID': room_id, 'creationDate': creation_date, 'roomSocketPort': room_socket_port})
diff --git a/backend/lib/server.py b/backend/lib/server.py
deleted file mode 100644
index a7941a9..0000000
--- a/backend/lib/server.py
+++ /dev/null
@@ -1,7 +0,0 @@
-from flask import Flask
-app = Flask(__name__)
-
-
-@app.route('/')
-def hello_world():
- return 'Hello, World!'
diff --git a/frontend/package.json b/frontend/package.json
index 3dc0855..045fcc0 100644
--- a/frontend/package.json
+++ b/frontend/package.json
@@ -16,6 +16,7 @@
},
"scripts": {
"start": "react-scripts start",
+ "start-api": "cd ../backend/lib && venv/bin/flask run --no-debugger",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
@@ -34,5 +35,6 @@
"last 1 firefox version",
"last 1 safari version"
]
- }
+ },
+ "proxy": "http://localhost:5000"
}
diff --git a/frontend/src/APIUtils.js b/frontend/src/APIUtils.js
index 2b9e6c3..0967684 100644
--- a/frontend/src/APIUtils.js
+++ b/frontend/src/APIUtils.js
@@ -3,23 +3,21 @@ import {
SERVER_PORT,
ROOM_ROUTES,
ROOM_ACTIONS,
-} from './shared_code/consts';
-import axios from 'axios';
+ API_ROUTES,
+} from "./shared_code/consts";
+import axios from "axios";
export const createRoom = async (roomDispatch, creatorID) => {
const req = { creatorID };
try {
- const res = await axios.post(
- `${SERVER_ADDRESS}:${SERVER_PORT}/${ROOM_ROUTES}/create`,
- req,
- );
+ const res = await axios.post(`/${API_ROUTES}/${ROOM_ROUTES}/create`, req);
roomDispatch(
ROOM_ACTIONS.initRoom(
res.data.roomID,
res.data.creationDate,
res.data.roomSocketPort,
- [],
- ),
+ []
+ )
);
} catch (err) {
window.alert(`Server giving us something wrong! ${err}`);
@@ -30,7 +28,7 @@ export const registerToRoom = async (
playerID,
playerName,
roomID,
- roomDispatch,
+ roomDispatch
) => {
try {
const res = await axios.get(
@@ -41,7 +39,7 @@ export const registerToRoom = async (
playerName,
roomID,
},
- },
+ }
);
const { error, errorMessage } = res.data;
if (error) {
@@ -52,8 +50,8 @@ export const registerToRoom = async (
roomID,
res.data.creationDate,
res.data.roomSocketPort,
- res.data.roomPlayersList,
- ),
+ res.data.roomPlayersList
+ )
);
}
} catch (err) {
diff --git a/frontend/src/shared_code/consts.js b/frontend/src/shared_code/consts.js
index 9118a61..b69b5a4 100644
--- a/frontend/src/shared_code/consts.js
+++ b/frontend/src/shared_code/consts.js
@@ -1,15 +1,16 @@
-export const SERVER_ADDRESS = 'http://localhost';
-export const SERVER_PORT = '8080';
-export const ROOM_ROUTES = 'room';
+export const SERVER_ADDRESS = "http://localhost";
+export const SERVER_PORT = "3000";
+export const API_ROUTES = "api";
+export const ROOM_ROUTES = "room";
export const PLAYER_ACTIONS = {
- generateUniqueID: { type: 'generateUniqueID' },
+ generateUniqueID: { type: "generateUniqueID" },
};
export const ROOM_ACTIONS = {
initRoom: (id, creationDate, socketPort, playersList) => {
return {
- type: 'initRoom',
+ type: "initRoom",
data: {
id,
creationDate,
@@ -18,17 +19,17 @@ export const ROOM_ACTIONS = {
},
};
},
- updatePlayerList: (playersList) => {
+ updatePlayerList: playersList => {
return {
- type: 'updatePlayerList',
+ type: "updatePlayerList",
data: {
playersList,
},
};
},
- setRoomID: (id) => {
+ setRoomID: id => {
return {
- type: 'setRoomId',
+ type: "setRoomId",
data: { id },
};
},