-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
75 lines (67 loc) · 1.84 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
from flask import Flask
import importlib
import routes.login as loginroute
import json
app = Flask(__name__)
with open('config.json') as f:
config = json.load(f)
sceretkey = config['panel']['sceret']
app.secret_key = sceretkey
def register_routes(app, routes):
for route in routes:
try:
module = importlib.import_module(route['module'])
if hasattr(module, route['function']):
view_func = getattr(module, route['function'])
app.add_url_rule(route['url'], view_func=view_func)
except ModuleNotFoundError:
print(f"Module not found: {route['module']}")
# Define the routes as a list of dictionaries
routes = [
{
'url': '/',
'module': 'routes.home',
'function': 'home'
},
{
'url': '/login',
'module': 'routes.login',
'function': 'login'
},
{
'url': '/login/callback',
'module': 'routes.login',
'function': 'callback'
},
{
'url': '/login/discord',
'module': 'routes.login',
'function': 'discord_login'
},
{
'url': '/dash/user/info',
'module': 'routes.userinfo',
'function': 'userinfo'
},
{
'url': '/dash',
'module': 'routes.dashboard',
'function': 'dashboard'
},
# API Routes
{
'url': '/api/logout',
'module': 'api.logout',
'function': 'logout'
},
{
'url': '/api/user/<int:userid>/coins',
'module': 'api.db',
'function': 'get_user_coins'
},
]
loginroute.init_oauth(app)
# Register the routes
register_routes(app, routes)
if __name__ == '__main__':
app.run(debug=True) # disable this if you want to run on production and run server on wsgi