hostname is set from commandline now

This commit is contained in:
Stefan Rupp 2020-12-11 22:12:27 +01:00
parent 342fa0cca3
commit c194164e3c
3 changed files with 16 additions and 4 deletions

View File

@ -4,16 +4,22 @@ import random
from app_instance import api from app_instance import api
from routes import * from routes import *
import wiz_game import wiz_game
import argparse
def main(): def main():
print("main started") print("main started")
parser = argparse.ArgumentParser()
parser.add_argument('--port', metavar='port', default=8001, type=int, help='the port to bind to')
parser.add_argument('--bindaddr', metavar='addr', default='127.0.0.1', help='the address to bind to')
args = parser.parse_args()
random.seed() random.seed()
wiz_game.the_game.start_game() wiz_game.the_game.start_game()
api.run(port=8001, address="127.0.0.1") api.run(port=args.port, address=args.bindaddr)
#api.run(port=8001, address="192.168.42.100")
exit(0) exit(0)

View File

@ -23,7 +23,13 @@
<![endif]--> <![endif]-->
<script> <script>
// let socket = new WebSocket("wss://cowiz.struppi.name/ws"); // let socket = new WebSocket("wss://cowiz.struppi.name/ws");
let socket = new WebSocket("ws://127.0.0.1:8001/ws"); if (window.location.hostname == '127.0.0.1') {
ws_schema = 'ws://';
}
else {
ws_schema = 'wss://';
}
let socket = new WebSocket(ws_schema+window.location.host+'/ws');
window.game_socket = socket window.game_socket = socket
socket.onopen = function(e) { socket.onopen = function(e) {

View File

@ -1,9 +1,9 @@
from app_instance import api from app_instance import api
from wiz_game import the_game from wiz_game import the_game
from starlette.websockets import WebSocketDisconnect from starlette.websockets import WebSocketDisconnect
import asyncio import asyncio
# don't define here, it's defined elsewhere! # don't define here, it's defined elsewhere!
#playing_lock = asyncio.Lock() #playing_lock = asyncio.Lock()