Skip to content

Commit 3d46bda

Browse files
committedJul 2, 2020
linking front-end and server.py
1 parent 2f8bd8c commit 3d46bda

File tree

3 files changed

+19
-3
lines changed

3 files changed

+19
-3
lines changed
 

‎server.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ const getApiAndEmit = (msg, socket) => {
4343
clearInterval(interval);
4444
} else {
4545
console.log('sending data: ', idx);
46-
socket.emit("getApiAndEmit", result.data.results[idx]);
46+
socket.emit("image", result.data.results[idx]);
4747
idx += 1;
4848
}
4949
}, 1000);

‎server/server.py

+16
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
from flask import Flask, jsonify, request, render_template, send_file
1919
from flask_compress import Compress
20+
from flask_cors import CORS, cross_origin
2021
from flask_socketio import SocketIO,send,emit,join_room
2122

2223
import argparse
@@ -46,6 +47,21 @@
4647
socketio = SocketIO(app)
4748
Compress(app)
4849

50+
#from here this is CORS to react problems
51+
CORS(app, support_credentials=True)
52+
@app.route('/api/test', methods=['POST', 'GET','OPTIONS'])
53+
@cross_origin(supports_credentials=True)
54+
def index():
55+
if(request.method=='POST'):
56+
some_json=request.get_json()
57+
return jsonify({"key":some_json})
58+
else:
59+
return jsonify({"GET":"GET"})
60+
61+
if __name__=="__main__":
62+
app.run(host='0.0.0.0', port=8080)
63+
#until here Cors problem- do not touch!
64+
4965
def get_image_links(main_keyword, download_dir,socket_id, num_requested = 100):
5066
"""get image links with selenium
5167

‎test-client/index.html

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@
2222
<script src="https://cdn.jsdelivr.net/npm/socket.io-client@2/dist/socket.io.js"></script>
2323
<div id="images"></div>
2424
<script>
25-
let socket = '51213';
26-
let socketSessionId = '51214';
25+
let socket = null;
26+
let socketSessionId = null;
2727

2828
document.getElementById("create-session").addEventListener('click', () => {
2929
console.log("Create session");

0 commit comments

Comments
 (0)