commit c309cd3f0de79eb8617e029f23f74c29765cf17d Author: dongho Date: Wed Dec 11 02:07:36 2024 +0900 first commit diff --git a/main.py b/main.py new file mode 100644 index 0000000..1208c9b --- /dev/null +++ b/main.py @@ -0,0 +1,27 @@ +from fastapi import FastAPI, APIRouter, Request +from fastapi.templating import Jinja2Templates +from security import security_router +import uvicorn + +app = FastAPI() +app.include_router(security_router) + +templates = Jinja2Templates(directory="templates") + + +@app.get("/") +async def read_root(request: Request): + data = "hi" + return templates.TemplateResponse( + request=request, + name="index.html", + contents={"data": data} + ) + +if __name__ == "__main__": + uvicorn.run( + "main:app", + host="0.0.0.0", + port=8080, + reload=True + ) diff --git a/security/__init__.py b/security/__init__.py new file mode 100644 index 0000000..6946f4e --- /dev/null +++ b/security/__init__.py @@ -0,0 +1 @@ +from .security import security_router diff --git a/security/__pycache__/__init__.cpython-310.pyc b/security/__pycache__/__init__.cpython-310.pyc new file mode 100644 index 0000000..455170e Binary files /dev/null and b/security/__pycache__/__init__.cpython-310.pyc differ diff --git a/security/__pycache__/security.cpython-310.pyc b/security/__pycache__/security.cpython-310.pyc new file mode 100644 index 0000000..eb0a697 Binary files /dev/null and b/security/__pycache__/security.cpython-310.pyc differ diff --git a/security/security.py b/security/security.py new file mode 100644 index 0000000..0c444ac --- /dev/null +++ b/security/security.py @@ -0,0 +1,17 @@ +from fastapi import APIRouter, Request +from fastapi.templating import Jinja2Templates + +security_router = APIRouter(prefix="/security", tags=["security"]) +templates = Jinja2Templates(directory="templates") + + +@security_router.get("/browser") +async def security_check_list(request: Request): + return templates.TemplateResponse( + request=request, name="browser_random_number.html", contents={"rand": "rand"} + ) + + +@security_router.get("/browser") +async def security_check_browser(): + return {"message": "checking browser security"} diff --git a/templates/base.html b/templates/base.html new file mode 100644 index 0000000..57e5344 --- /dev/null +++ b/templates/base.html @@ -0,0 +1,46 @@ + + + + + + + + {% block title %}My FastAPI App{% endblock %} + {% block css %} + {% endblock %} + + + + + + + {% block content %} + {% endblock %} + {% block js %} + {% endblock %} + + + + diff --git a/templates/browser_random_number.html b/templates/browser_random_number.html new file mode 100644 index 0000000..aa9c971 --- /dev/null +++ b/templates/browser_random_number.html @@ -0,0 +1,198 @@ +{% extends "base.html" %} + +{% block title %}Browser Random Generation{% endblock %} + +{% block content %} +
+
+

Detected Browser: Something

+
+
+ +
+
+{% endblock %} + +{% block js %} + + + +{% endblock %} diff --git a/templates/browser_security_random_number.html b/templates/browser_security_random_number.html new file mode 100644 index 0000000..fb908c2 --- /dev/null +++ b/templates/browser_security_random_number.html @@ -0,0 +1,19 @@ + + + + + {% block title %}My FastAPI App{% endblock %} + + + + {% block content %} + {% endblock %} + + {# Footer #} + + + {% block js %}{% endblock %} + + diff --git a/templates/index.html b/templates/index.html new file mode 100644 index 0000000..df200c0 --- /dev/null +++ b/templates/index.html @@ -0,0 +1,14 @@ +{% extends "base.html" %} + +{% block title %}Home Page{% endblock %} + +{% block content %} +
+

Hello World

+
+ +{% endblock %} + +{% block css %} +{{ super() }} +{% endblock %}