-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
122 lines (94 loc) · 3.57 KB
/
app.py
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
from logging.config import dictConfig
import flask
from flask import Flask, render_template, redirect, Blueprint, url_for
from apis import api_blueprint
from model.models import db
import os
def get_env_variable(name):
try:
return os.environ[name]
except KeyError:
message = "Expected environment variable '{}' not set.".format(name)
raise Exception(message)
def get_db_uri():
#postgres_url = get_env_variable("POSTGRES_URL")
#postgres_user = get_env_variable("POSTGRES_USER")
#postgres_pw = get_env_variable("POSTGRES_PW")
#postgres_db = get_env_variable("POSTGRES_DB")
postgres_url = "localhost"
postgres_user = "geco_ro"
postgres_pw = "geco78"
postgres_db = "gmql_meta_new13"
return 'postgresql+psycopg2://{user}:{pw}@{url}/{db}'.format(user=postgres_user,
pw=postgres_pw,
url=postgres_url,
db=postgres_db)
dictConfig({
'version': 1,
'formatters': {'default': {
'format': '[%(asctime)s] %(levelname)s in %(module)s:%(lineno)d: %(message)s',
}},
'handlers': {'wsgi': {
'class': 'logging.StreamHandler',
'stream': 'ext://flask.logging.wsgi_errors_stream',
'formatter': 'default'
}},
'root': {
'level': 'DEBUG',
'handlers': ['wsgi']
}
})
base_url = '/genosurf/'
api_url = base_url + 'api'
repo_static_url = base_url + 'repo_static'
my_app = Flask(__name__)
my_app.config['SQLALCHEMY_DATABASE_URI'] = get_db_uri()
my_app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
my_app.config['SQLALCHEMY_POOL_SIZE'] = 1
my_app.config['SQLALCHEMY_MAX_OVERFLOW'] = 30
db.init_app(my_app)
simple_page = Blueprint('root_pages', __name__,
static_folder='../vue-metadata/dist/static',
template_folder='../vue-metadata/dist')
graph_pages = Blueprint('static', __name__,
# static_url_path='/',
static_folder='./repo_static/',
# template_folder='../vue-metadata/dist'
)
# base url defined in apis init
@simple_page.route('/')
def index():
flask.current_app.logger.info("serve index")
return render_template('index.html')
# Make a "catch all route" so all requests match our index.html file.
# This lets us use the new history APIs in the browser.
@simple_page.route('/', defaults={'path': ''})
@simple_page.route('/<path:path>')
def redirect_all(path):
return redirect(url_for('.index'))
# register blueprints
my_app.register_blueprint(api_blueprint, url_prefix=api_url)
my_app.register_blueprint(graph_pages, url_prefix=repo_static_url)
my_app.register_blueprint(simple_page, url_prefix=base_url)
my_app.app_context().push()
# redirect all to base url
@my_app.route('/', defaults={'path': ''})
@my_app.route('/<path:path>')
def index_all(path):
return redirect(base_url)
# if __name__ == '__main__':
# my_app.run()
# prevent cached responses
@my_app.after_request
def add_header(r):
"""
Add headers to both force latest IE rendering engine or Chrome Frame,
and also to cache the rendered page for 10 minutes.
"""
if "Cache-Control" not in r.headers:
r.cache_control.max_age = 300 # 5 min
# r.headers["Cache-Control"] = "no-cache, no-store, must-revalidate"
# r.headers["Pragma"] = "no-cache"
# r.headers["Expires"] = "0"
# r.headers['Cache-Control'] = 'public, max-age=0'
return r