-
Notifications
You must be signed in to change notification settings - Fork 0
/
handler.py
46 lines (34 loc) · 1.07 KB
/
handler.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
# -*- coding: utf-8 -*-
import importlib
import os
import sys
from flask import Flask, send_file
from flask_cors import CORS
import web # pylint: disable=W0611
from Monitor import Monitor
sys.path.insert(0, os.path.join(os.path.dirname(os.path.realpath(__file__)), 'web'))
sys.path.insert(0, os.path.join(os.path.dirname(os.path.realpath(__file__)), 'private', 'web'))
os.environ['TZ'] = 'UTC'
M = Monitor()
app = Flask(__name__)
CORS(app)
@app.route('/')
def index():
return website('index')
@app.route('/<path>', methods=['GET', 'POST'])
def website(path):
if path.endswith('.js'):
return send_file(os.path.join(os.path.dirname(os.path.realpath(__file__)), 'web', path))
try:
module = importlib.import_module(path)
print(module)
except ImportError as e:
M.log('[handler][error] {}'.format(e))
return 'No such module.'
try:
return module.web()
except AttributeError as e:
M.log('[handler][error] {}'.format(e))
return "This module doesn't have web."
if __name__ == "__main__":
app.run()