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">
<div class="input-group">
<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 class="input-group">
<label for="run-field">Run id</label>
@ -21,8 +21,8 @@
</div>
<div class="input-group">
<input type="button" name="start" value="Start" onClick="call_backend" />
<input type="button" name="handoff" value="Handoff" onClick="call_backend" />
<input type="button" name="start" value="Start" onclick="call_backend()" />
<input type="button" name="handoff" value="Handoff" onclick="call_backend()" />
</div>
</form>

View file

@ -1,18 +1,20 @@
let call_backend = function(e) {
console.log("Call backend");
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 link = document.forms["link"]["link-field"].value;
xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
document.getElementById("result").innerHTML = xmlhttp.responseText;
x = new XMLHttpRequest();
x.onreadystatechange = function() {
if (x.readyState === 4) {
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
from flask import Flask, render_template
from flask_cors import CORS
sio = socketio.Server()
app = Flask(__name__)
cors = CORS(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

View file

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