From 01d2dc71065ef5b87c07332ad9bafa256b7ecf8e Mon Sep 17 00:00:00 2001 From: Enzo Simonnet <enzosim@laposte.net> Date: Tue, 3 Jan 2023 17:35:15 +0100 Subject: [PATCH] update CORS --- README.md | 3 ++- wikstraktor_server.py | 3 +++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index ceef637..08617a0 100644 --- a/README.md +++ b/README.md @@ -20,13 +20,14 @@ This project does depend on python packages. * [```pip install importlib```](https://pypi.org/project/importlib/) Optional (for python 2.*) ### Wikstraktor Server -If you want wikstraktor as a server, you need to install [flask](https://flask.palletsprojects.com/en/2.0.x/installation/), and best practice is to do so in a [virtual environment](https://docs.python.org/3/library/venv.html#module-venv). +If you want wikstraktor as a server, you need to install [flask](https://flask.palletsprojects.com/en/2.0.x/installation/) and [flask-cors](https://flask-cors.readthedocs.io/en/latest/), and best practice is to do so in a [virtual environment](https://docs.python.org/3/library/venv.html#module-venv). The following commands are extracted from the aforementionned documentation, it is probably more secure to click on the link and follow the modules documentation : ```bash python3 -m venv wikstraktorenv #create wikstraktorenv environment . wikstraktorenv/bin/activate #activate environment pip install Flask #install Flask +pip install -U flask-cors #install Flask cors ``` ## Use diff --git a/wikstraktor_server.py b/wikstraktor_server.py index 0aae886..3e63995 100755 --- a/wikstraktor_server.py +++ b/wikstraktor_server.py @@ -2,10 +2,13 @@ from flask import Flask #server from flask import request #to handle the different http requests from flask import Response #to reply (we could use jsonify as well but we handled it) +from flask_cors import CORS #to allow cross-origin requests from wikstraktor import Wikstraktor import wikstraktor_server_config as config app = Flask(__name__) +CORS(app) + @app.route('/', methods=['GET']) def index(): c = request.remote_addr -- GitLab