-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
52 lines (43 loc) · 1.75 KB
/
main.py
File metadata and controls
52 lines (43 loc) · 1.75 KB
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
from fastapi import FastAPI, Request, status
from fastapi.middleware.cors import CORSMiddleware
from fastapi.staticfiles import StaticFiles
from fastapi.templating import Jinja2Templates
from starlette.templating import _TemplateResponse # noqa
from api.routers.api.create import api as api_create
from api.routers.api.hex import api as api_hex
from api.routers.api.info import api as api_info
from api.routers.api.packets import api as api_packets
from api.routers.version import version
app = FastAPI(
title="Packet Helper Next",
description="Packet Helper API helps you to decode hex into packets with description 🚀",
version="0.1",
license_info={
"name": "GPL v2.0",
"url": "https://github.com/PacketHelper/packet-helper-next/blob/main/LICENSE",
},
)
app.add_middleware(
CORSMiddleware,
allow_origins=["*"],
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
app.mount("/static", StaticFiles(directory="static"), name="static")
# rest api
# /api/*
router_api_config = {"prefix": "/api", "tags": ["api"]}
for api_router in (api_create, api_hex, api_info, api_packets):
app.include_router(api_router, **router_api_config)
# /*
app.include_router(version)
templates = Jinja2Templates(directory="static")
@app.get("/", include_in_schema=False, status_code=status.HTTP_200_OK)
def get_root(request: Request) -> _TemplateResponse:
"""Return Vue single page"""
return templates.TemplateResponse("index.html", {"request": request})
@app.get("/hex/{hex_string}", include_in_schema=False, status_code=status.HTTP_200_OK)
def get_hex(request: Request) -> _TemplateResponse:
"""Return specific path for Vue single-page"""
return templates.TemplateResponse("index.html", {"request": request})