-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrouter.py
36 lines (33 loc) · 1.59 KB
/
router.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
import aiohttp_cors
from controllers import auth, main_controller
def routes(app):
# Set up CORS
cors = aiohttp_cors.setup(
app,
defaults={
"*": aiohttp_cors.ResourceOptions(
allow_methods=("*"),
allow_credentials=True,
expose_headers=("*",),
allow_headers=("*"),
max_age=3600,
)
}
)
# Define routes and their handlers
route_definitions = [
{"method": "GET", "path": "/", "handler": main_controller.index},
{"method": "POST", "path": "/auth", "handler": auth.login},
{"method": "POST", "path": "/create-pool", "handler": main_controller.create_pool},
{"method": "POST", "path": "/delete-pool", "handler": main_controller.delete_pool},
{"method": "GET", "path": "/devices", "handler": main_controller.get_storage_info},
{"method": "GET", "path": "/status", "handler": main_controller.check_status},
{"method": "GET", "path": "/io-status", "handler": main_controller.get_io_status},
{"method": "POST", "path": "/add-disk", "handler": main_controller.add_disk},
{"method": "POST", "path": "/add-spare-disk", "handler": main_controller.add_spare_disk},
{"method": "POST", "path": "/replace-disk", "handler": main_controller.replace_disk},
{"method": "POST", "path": "/mountpoint", "handler": main_controller.set_mountpoint},
]
# Add routes and attach CORS
for route in route_definitions:
cors.add(app.router.add_route(route["method"], route["path"], route["handler"]))