From 9a9669d87dd9c8fd44b5559ea6145b1846c7dd89 Mon Sep 17 00:00:00 2001 From: Maxime Bloch Date: Fri, 27 Sep 2019 15:20:10 +0200 Subject: [PATCH] add cors to server, fix client requests --- client/index.html | 6 +++--- client/index.js | 22 ++++++++++++---------- watcher/app.py | 2 ++ watcher/requirements.txt | 1 + 4 files changed, 18 insertions(+), 13 deletions(-) diff --git a/client/index.html b/client/index.html index bbc989b..f67053f 100644 --- a/client/index.html +++ b/client/index.html @@ -9,7 +9,7 @@
- +
@@ -21,8 +21,8 @@
- - + +
diff --git a/client/index.js b/client/index.js index b0c619d..52f5972 100644 --- a/client/index.js +++ b/client/index.js @@ -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(); +}; diff --git a/watcher/app.py b/watcher/app.py index ee3538a..2ce46ee 100644 --- a/watcher/app.py +++ b/watcher/app.py @@ -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 diff --git a/watcher/requirements.txt b/watcher/requirements.txt index 23c5fdc..426a190 100644 --- a/watcher/requirements.txt +++ b/watcher/requirements.txt @@ -1,2 +1,3 @@ flask +flask-cors python-socketio