From b595fad677e4c76fb98ce72909b04ab686a73133 Mon Sep 17 00:00:00 2001 From: Josh Ferrerra Date: Wed, 17 May 2017 10:00:48 -0700 Subject: [PATCH 1/2] allow cors for related products request --- intelligence/anthill/Dockerfile | 2 +- intelligence/anthill/src/router.py | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/intelligence/anthill/Dockerfile b/intelligence/anthill/Dockerfile index 9985b24107..325e07c217 100644 --- a/intelligence/anthill/Dockerfile +++ b/intelligence/anthill/Dockerfile @@ -3,7 +3,7 @@ FROM ubuntu:16.04 RUN apt-get update && apt-get install -y python3 python3-pip \ && apt-get clean -RUN pip3 install numpy scipy Flask neo4j-driver==1.1.0 +RUN pip3 install numpy scipy Flask flask-cors neo4j-driver==1.1.0 RUN mkdir -p /anthill ADD . /anthill/ diff --git a/intelligence/anthill/src/router.py b/intelligence/anthill/src/router.py index 65dd6a3bd1..80dc98f210 100644 --- a/intelligence/anthill/src/router.py +++ b/intelligence/anthill/src/router.py @@ -1,6 +1,7 @@ import os from flask import Flask, request, jsonify +from flask_cors import cross_origin from managers.Prod_Prod_Manager import Prod_Prod_Manager from util.ES_Client import ES_Client from util.InvalidUsage import InvalidUsage @@ -40,6 +41,7 @@ def rec_prod_prod(prod_id): return jsonify(resp) @APP.route('/public/prod-prod/full/', methods=['GET']) +@cross_origin() def rec_prod_prod_full(prod_id): """rec_prod_prod_full returns a list of full products from elasticsearch From f20a8ea2a6ba946091bee314f693336d030b4074 Mon Sep 17 00:00:00 2001 From: Josh Ferrerra Date: Thu, 18 May 2017 10:02:48 -0700 Subject: [PATCH 2/2] use header instead of flask-cors --- intelligence/anthill/Dockerfile | 2 +- intelligence/anthill/src/router.py | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/intelligence/anthill/Dockerfile b/intelligence/anthill/Dockerfile index 325e07c217..9985b24107 100644 --- a/intelligence/anthill/Dockerfile +++ b/intelligence/anthill/Dockerfile @@ -3,7 +3,7 @@ FROM ubuntu:16.04 RUN apt-get update && apt-get install -y python3 python3-pip \ && apt-get clean -RUN pip3 install numpy scipy Flask flask-cors neo4j-driver==1.1.0 +RUN pip3 install numpy scipy Flask neo4j-driver==1.1.0 RUN mkdir -p /anthill ADD . /anthill/ diff --git a/intelligence/anthill/src/router.py b/intelligence/anthill/src/router.py index 80dc98f210..3a5ff5306f 100644 --- a/intelligence/anthill/src/router.py +++ b/intelligence/anthill/src/router.py @@ -1,7 +1,6 @@ import os -from flask import Flask, request, jsonify -from flask_cors import cross_origin +from flask import Flask, request, jsonify, make_response from managers.Prod_Prod_Manager import Prod_Prod_Manager from util.ES_Client import ES_Client from util.InvalidUsage import InvalidUsage @@ -41,7 +40,6 @@ def rec_prod_prod(prod_id): return jsonify(resp) @APP.route('/public/prod-prod/full/', methods=['GET']) -@cross_origin() def rec_prod_prod_full(prod_id): """rec_prod_prod_full returns a list of full products from elasticsearch @@ -50,7 +48,9 @@ def rec_prod_prod_full(prod_id): size_param = int(request.args.get('size', 10)) from_param = int(request.args.get('from', 0)) full_resp = PP_MANAGER.recommend_full(prod_id, channel_id, from_param, size_param) - return jsonify(full_resp) + resp = make_response(jsonify(full_resp)) + resp.headers['Allow-Control-Allow-Origin'] = '*' + return resp @APP.route('/public/cust-prod/', methods=['GET']) def rec_cust_prod(cust_id):