Skip to content

Commit

Permalink
Add CORS (#270)
Browse files Browse the repository at this point in the history
* Extract flask setup method

* Remove venv caching

* Add CORS
  • Loading branch information
c-w authored Dec 26, 2019
1 parent c12370d commit 5a008c8
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 11 deletions.
9 changes: 3 additions & 6 deletions makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,9 @@ PY_ENV ?= ./venv
.PHONY: venv tests
default: ci

$(PY_ENV)/requirements.txt.out: requirements.txt requirements-dev.txt
if [ ! -d $(PY_ENV) ]; then python3 -m venv $(PY_ENV) && $(PY_ENV)/bin/pip install -U pip wheel | tee $(PY_ENV)/requirements.txt.out; fi
$(PY_ENV)/bin/pip install -r requirements.txt | tee $(PY_ENV)/requirements.txt.out
$(PY_ENV)/bin/pip install -r requirements-dev.txt | tee $(PY_ENV)/requirements.txt.out

venv: $(PY_ENV)/requirements.txt.out
venv: requirements.txt requirements-dev.txt
if [ ! -d $(PY_ENV) ]; then python3 -m venv $(PY_ENV) && $(PY_ENV)/bin/pip install -U pip wheel; fi
$(PY_ENV)/bin/pip install -r requirements.txt -r requirements-dev.txt

tests: venv
LOKOLE_LOG_LEVEL=CRITICAL $(PY_ENV)/bin/coverage run -m nose2 -v && \
Expand Down
16 changes: 12 additions & 4 deletions opwen_email_server/integration/wsgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

from applicationinsights.flask.ext import AppInsights
from connexion import App
from flask import Flask
from flask_cors import CORS

from opwen_email_server import config

Expand All @@ -18,14 +20,20 @@ def build_app(apis, host=_host, port=_port, ui=_ui):
for api in apis:
app.add_api(api)

app.app.config['APPINSIGHTS_INSTRUMENTATIONKEY'] = config.APPINSIGHTS_KEY
app.app.config['APPINSIGHTS_ENDPOINT_URI'] = config.APPINSIGHTS_HOST
app.app.config['APPINSIGHTS_DISABLE_TRACE_LOGGING'] = True
AppInsights(app.app)
_configure_flask(app.app)

return app


def _configure_flask(app: Flask):
app.config['APPINSIGHTS_INSTRUMENTATIONKEY'] = config.APPINSIGHTS_KEY
app.config['APPINSIGHTS_ENDPOINT_URI'] = config.APPINSIGHTS_HOST
app.config['APPINSIGHTS_DISABLE_TRACE_LOGGING'] = True
AppInsights(app)

CORS(app)


def _cli():
from argparse import ArgumentParser
from argparse import FileType
Expand Down
4 changes: 3 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
Flask==1.1.1
Flask-Cors==3.0.8
Pillow==6.2.1
apache-libcloud==2.6.0
applicationinsights==0.11.9
beautifulsoup4==4.8.1
cached-property==1.5.1
connexion[flask,swagger-ui]==2.4.0
connexion[swagger-ui]==2.4.0
environs==6.1.0
msgpack==0.6.2
python-http-client==3.2.1
Expand Down

0 comments on commit 5a008c8

Please sign in to comment.