-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
executable file
·73 lines (59 loc) · 1.98 KB
/
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
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
from fastapi.responses import JSONResponse, RedirectResponse
from fastapi.openapi.utils import get_openapi
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
from routers.bruteforce_router import app as bruteforce
from routers.encryption_router import app as encryption
from routers.forensic_router import app as forensic
from routers.proxy_router import app as proxy
from routers.wp_router import app as wp
from routers.crawler_router import app as crawler
from routers.network_router import app as network
# FastApi Instance
app = FastAPI()
# CorsMiddleware Handling
app.add_middleware(
CORSMiddleware,
allow_origins=["*"],
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
@app.get('/', tags=["System"], response_class=RedirectResponse)
async def swagger():
return "/docs"
@app.get('/version', tags=["System"], response_class=JSONResponse)
async def version():
return {"version": "1.2.6"}
app.include_router(bruteforce)
app.include_router(encryption)
app.include_router(forensic)
app.include_router(proxy)
app.include_router(wp)
app.include_router(crawler)
app.include_router(network)
# this handler return all errors and they type's
@app.exception_handler(Exception)
async def handle_exception(request, exc: Exception):
return JSONResponse({
"status": "failed",
"data": {
"detail": str(exc),
"exc_type": str(type(exc).__name__)
}}, status_code=500)
def custom_openapi():
if app.openapi_schema:
return app.openapi_schema
# for route in app.routes:
# body_field = getattr(route, 'body_field', None)
# if body_field:
# body_field.type_.__name__ = 'name'
openapi_schema = get_openapi(
title="Unsafe Rest-API",
version="1.2.2",
description="RESTful API Service for unsafe Module",
routes=app.routes,
)
app.openapi_schema = openapi_schema
return app.openapi_schema
app.openapi = custom_openapi