add cors to server, fix client requests

This commit is contained in:
Maxime Bloch 2019-09-27 15:20:10 +02:00
parent 5228879c96
commit 9a9669d87d
No known key found for this signature in database
GPG key ID: CE32A7D95B7D6418
4 changed files with 18 additions and 13 deletions

View file

@ -9,7 +9,7 @@
<form name="link"> <form name="link">
<div class="input-group"> <div class="input-group">
<label for="url-field">Watch server url</label> <label for="url-field">Watch server url</label>
<input name="url-field" type="text" required></input> <input name="url-field" type="text" value="localhost:5000" required></input>
</div> </div>
<div class="input-group"> <div class="input-group">
<label for="run-field">Run id</label> <label for="run-field">Run id</label>
@ -21,8 +21,8 @@
</div> </div>
<div class="input-group"> <div class="input-group">
<input type="button" name="start" value="Start" onClick="call_backend" /> <input type="button" name="start" value="Start" onclick="call_backend()" />
<input type="button" name="handoff" value="Handoff" onClick="call_backend" /> <input type="button" name="handoff" value="Handoff" onclick="call_backend()" />
</div> </div>
</form> </form>

View file

@ -1,18 +1,20 @@
let call_backend = function(e) { let call_backend = function(e) {
console.log("Call backend");
type = event.target.getAttribute('name'); type = event.target.getAttribute('name');
console.log(type);
var url = document.forms["link"]["url-field"].value; var url_base = document.forms["link"]["url-field"].value;
var run = document.forms["link"]["run-field"].value; var run = document.forms["link"]["run-field"].value;
var link = document.forms["link"]["link-field"].value; var link = document.forms["link"]["link-field"].value;
xmlhttp = new XMLHttpRequest(); x = new XMLHttpRequest();
xmlhttp.onreadystatechange = function() { x.onreadystatechange = function() {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) { if (x.readyState === 4) {
document.getElementById("result").innerHTML = xmlhttp.responseText; console.log("response: " + x.responseText);
document.getElementById("result").innerHTML = x.responseText;
}; };
}; };
xmlhttp.open("POST", url + "/link/" (type==="start" ? "start" : "handoff") + "/" + run + "/" + link, true);
xmlhttp.send(); var url = "http://" + url_base + "/link/" + (type === "start" ? "start" : "handoff") + "/" + run + "/" + link;
} // console.log(url);
x.open("GET", url, true);
x.send();
};

View file

@ -2,9 +2,11 @@ from time import time
import socketio import socketio
from flask import Flask, render_template from flask import Flask, render_template
from flask_cors import CORS
sio = socketio.Server() sio = socketio.Server()
app = Flask(__name__) app = Flask(__name__)
cors = CORS(app)
app.wsgi_app = socketio.WSGIApp(sio, app.wsgi_app) app.wsgi_app = socketio.WSGIApp(sio, app.wsgi_app)
# We request users to send the run number to prevent accidentially getting old requests from a previous run # We request users to send the run number to prevent accidentially getting old requests from a previous run

View file

@ -1,2 +1,3 @@
flask flask
flask-cors
python-socketio python-socketio