-
Notifications
You must be signed in to change notification settings - Fork 3
/
main.py
35 lines (26 loc) · 940 Bytes
/
main.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
from flask import Flask, send_from_directory
import importlib
app = Flask(__name__,template_folder='src/common/template/static')
@app.route('/', defaults={'path': ''})
@app.route('/<path:path>')
def router(path):
# route requests to "foo/bar/si" to
# `si.py` in `bar` directory, which is in `foo` directory,
# which is inside `root` directory of `roots`
if path == '':
return router('index')
moduleObjectToRouteTo = None
modulePathToRouteTo = path
if '/' in modulePathToRouteTo:
modulePathToRouteTo = modulePathToRouteTo.replace('/', '.')
try:
moduleObjectToRouteTo = importlib.import_module('routes.root.'+modulePathToRouteTo)
except ModuleNotFoundError:
#try if it's a static file
return send_from_directory('static', path)
return moduleObjectToRouteTo.main()
@app.errorhandler(404)
def fourOhFour(e):
return router('404')
from waitress import serve
serve(app, host='0.0.0.0', port=80)