-
Notifications
You must be signed in to change notification settings - Fork 24
Expand file tree
/
Copy pathapp.py
More file actions
77 lines (59 loc) · 1.67 KB
/
app.py
File metadata and controls
77 lines (59 loc) · 1.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# -*- coding: utf-8 -*-
"""
Main QuantifiedCode app.
"""
from __future__ import unicode_literals
from __future__ import absolute_import
import sys
import re
import argparse
import urlparse
from flask import Flask,request
from werkzeug.wsgi import DispatcherMiddleware
from quantifiedcode.settings import settings, backend
from quantifiedcode.backend.app import get_app as get_backend_app
from quantifiedcode.frontend.app import get_app as get_frontend_app
"""
Run the backend and the frontend as a single Flask application.
You might need to change 'settings.js' in the frontend to accommodate for the
changed API URL.
"""
def get_app(settings):
app = Flask(__name__)
empty_app = Flask(__name__)
app.wsgi_app = DispatcherMiddleware(empty_app, {
'/api': get_backend_app(settings),
settings.get('frontend.url') : get_frontend_app(settings),
})
return app
if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument(
dest=u'host',
nargs=u'?',
default=u'0.0.0.0:5000',
)
args = parser.parse_args(sys.argv[1:])
if u':' in args.host:
host, port = args.host.split(':', 1)
port = int(port)
else:
url = urlparse.urlparse(settings.get('url'))
if url.port:
port = url.port
else:
port = 5000
if url.hostname:
host = url.hostname
else:
host = '0.0.0.0'
settings.initialize(backend)
app = get_app(settings)
app.run(
debug=settings.get('debug', False),
host=host,
port=port,
processes=1,
threaded = False,
use_reloader=True
)