Skip to content
Snippets Groups Projects
Unverified Commit d0e87e46 authored by Sebastian Höffner's avatar Sebastian Höffner
Browse files

Allowing web-openccg to be run in a subdirectory.

This is achieved by mounting it at the directory specified using the
environment variable APPLICATION_ROOT.
parent 60c5646d
No related branches found
No related tags found
No related merge requests found
import json
import os
import uuid
from flask import Flask, render_template, request
from flask import Flask, render_template, request, redirect
from werkzeug.wsgi import DispatcherMiddleware
import wccg
import graphs
app = Flask(__name__)
def create_redirecting_app(to):
"""Creates a dummy flask app which redirects to 'to' for the root url."""
app = Flask('redirector')
@app.route('/')
def index():
return redirect(to, code=301)
return app
def create_app():
"""Initializes the Flask app.
Reads the environment variable APPLICATION_ROOT and creates a
DispatcherMiddleware if it is set to something different than /.
This allows to mount the app in a subdirectory.
"""
app = Flask(__name__)
app.config['APPLICATION_ROOT'] = os.environ.get('APPLICATION_ROOT', '/')
if app.config['APPLICATION_ROOT'] != '/':
if app.config['APPLICATION_ROOT'].endswith('/'):
app.config['APPLICATION_ROOT'] = app.config['APPLICATION_ROOT'][:-1]
redirector = create_redirecting_app(app.config['APPLICATION_ROOT'])
mounts = {
app.config['APPLICATION_ROOT']: app.wsgi_app
}
app.wsgi_app = DispatcherMiddleware(redirector, mounts)
app.logger.info('APPLICATION_ROOT=%s', app.config['APPLICATION_ROOT'])
return app
app = create_app()
def create_response(sentence):
......@@ -22,11 +62,12 @@ def create_response(sentence):
content = wccg.parse(sentence)
response = {
'version': '2.1.0',
'version': '2.2.0',
'application': 'web-openccg',
'uuid': str(uuid.uuid4())
}
response.update(content)
response.update(graphs.create_graphs(response['json_parses']))
return response
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment