Skip to content

Commit

Permalink
[patch] UMA-35: set weksocket ulr based on env config
Browse files Browse the repository at this point in the history
  • Loading branch information
jrsmth committed Nov 27, 2023
1 parent 17242d2 commit b2fda98
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 8 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
# Releases
<!-- @LatestFirst -->

## [0.5.2] - 27/11/23
- UMA-35: [Bug] Set websocket URL based on environment

## [0.5.1] - 27/11/23
- UMA-34: [Bug] Broken deployment due to missing gevent installation

Expand Down Expand Up @@ -87,4 +90,5 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
[0.4.0]: https://github.com/jrsmth/ultima/compare/0.3.2...0.4.0
[0.4.1]: https://github.com/jrsmth/ultima/compare/0.4.0...0.4.1
[0.5.0]: https://github.com/jrsmth/ultima/compare/0.4.1...0.5.0
[0.5.1]: https://github.com/jrsmth/ultima/compare/0.5.0...0.5.1
[0.5.1]: https://github.com/jrsmth/ultima/compare/0.5.0...0.5.1
[0.5.2]: https://github.com/jrsmth/ultima/compare/0.5.1...0.5.2
3 changes: 3 additions & 0 deletions src/app/config/config.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
class Config(object):
APP_URL = "http://localhost:8080"
REDIS_URL = "redis://@localhost:6379/0"


class DevConfig(Config):
APP_URL = "http://localhost:8080"
REDIS_URL = "rediss://red-cklv99jj89us738u33i0:[email protected]:6379"


class ProductionConfig(Config):
APP_URL = "https://www.ultima.jrsmth.io/"
REDIS_URL = 'redis://red-cklv99jj89us738u33i0:6379'
5 changes: 3 additions & 2 deletions src/app/game/game.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import json
import random

from flask import render_template, url_for, redirect, Blueprint, Response
from flask import render_template, Blueprint, Response, current_app

from src.app.model.board.board import map_to_symbol
from src.app.model.board.threeboard import ThreeBoard
Expand All @@ -21,10 +21,11 @@ def construct_blueprint(messages, socket, redis):

@game_page.route("/game/<game_id>/<user_id>")
def game(game_id, user_id):
app_url = current_app.config["APP_URL"]
update_game_state(game_id, user_id + ' has joined the game')
check_status(game_id)

return render_template("game.html", gameId=game_id, userId=user_id, version=__version__)
return render_template("game.html", appUrl=app_url, gameId=game_id, userId=user_id, version=__version__)

@socket.on('restart')
def restart(message):
Expand Down
2 changes: 1 addition & 1 deletion src/app/util/redis.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def get_complex(self, key):


# Standardises a JSON string for conversion into a python dict
def standardise(value): # FixMe :: bit dodgy
def standardise(value): # FixMe :: bit dodgy
# Convert Python `False` to JSON-standard `true`
standardised = str(value).replace("False,", "false,").replace("True,", "true,")

Expand Down
7 changes: 3 additions & 4 deletions src/resources/static/scripts/game.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
let userId;
let gameState;
let socket;
let appUrl;

async function init(gameId) {
// Retrieve game state
Expand Down Expand Up @@ -224,11 +225,9 @@ function restart() {
}

function connectSocket(gameId) {
// const socket = io();
socket = io.connect('http://localhost:8080'); // ??
socket = io.connect(appUrl);

// const socket = io();
console.log(socket);
console.log(socket); // FixMe

socket.on('connect', function() {
console.log('connected');
Expand Down
2 changes: 2 additions & 0 deletions src/resources/templates/game.html
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,9 @@
<script src="{{ url_for('static', filename='scripts/game.js') }}"></script>
<script>
$(document).ready(function() {
appUrl = "{{ appUrl }}";
userId = "{{ userId }}";

enableCopy();
connectSocket("{{ gameId }}");
init("{{ gameId }}");
Expand Down

0 comments on commit b2fda98

Please sign in to comment.