Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -125,3 +125,7 @@ dist
npm-debug.log*
yarn-debug.log*
yarn-error.log*
/venv
/__pycache__
venv
__pycache__
4 changes: 4 additions & 0 deletions .idea/Mafia.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions backend/lib/api.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from flask import Flask
from lib.routes import api

app = Flask(__name__)

app.register_blueprint(api)
Empty file added backend/lib/models/__init__.py
Empty file.
16 changes: 16 additions & 0 deletions backend/lib/routes.py
Original file line number Diff line number Diff line change
@@ -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})
7 changes: 0 additions & 7 deletions backend/lib/server.py

This file was deleted.

4 changes: 3 additions & 1 deletion frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -34,5 +35,6 @@
"last 1 firefox version",
"last 1 safari version"
]
}
},
"proxy": "http://localhost:5000"
}
22 changes: 10 additions & 12 deletions frontend/src/APIUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}`);
Expand All @@ -30,7 +28,7 @@ export const registerToRoom = async (
playerID,
playerName,
roomID,
roomDispatch,
roomDispatch
) => {
try {
const res = await axios.get(
Expand All @@ -41,7 +39,7 @@ export const registerToRoom = async (
playerName,
roomID,
},
},
}
);
const { error, errorMessage } = res.data;
if (error) {
Expand All @@ -52,8 +50,8 @@ export const registerToRoom = async (
roomID,
res.data.creationDate,
res.data.roomSocketPort,
res.data.roomPlayersList,
),
res.data.roomPlayersList
)
);
}
} catch (err) {
Expand Down
19 changes: 10 additions & 9 deletions frontend/src/shared_code/consts.js
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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 },
};
},
Expand Down