mirror of
https://codeberg.org/Freedium-cfd/web.git
synced 2026-03-11 09:04:37 +00:00
35 lines
No EOL
1.2 KiB
Python
35 lines
No EOL
1.2 KiB
Python
from fastapi import Request
|
|
from fastapi.responses import HTMLResponse
|
|
from starlette.middleware.base import BaseHTTPMiddleware
|
|
from server import maintenance_mode
|
|
|
|
HTML_RESPONSE_BODY = """
|
|
<!doctype html>
|
|
<title>Site Maintenance</title>
|
|
<style>
|
|
body { text-align: center; padding: 150px; }
|
|
h1 { font-size: 50px; }
|
|
body { font: 20px Helvetica, sans-serif; color: #333; }
|
|
article { display: block; text-align: left; width: 650px; margin: 0 auto; }
|
|
a { color: #dc8100; text-decoration: none; }
|
|
a:hover { color: #333; text-decoration: none; }
|
|
</style>
|
|
|
|
<article>
|
|
<h1>We’ll be back soon!</h1>
|
|
<div>
|
|
<p>Sorry for the inconvenience but we’re performing some maintenance at the moment. If you need to you can always <a href="mailto:#admin@freedium.cfd">contact us</a>, otherwise we’ll be back online shortly!</p>
|
|
<p>— Freedium developers</p>
|
|
</div>
|
|
</article>
|
|
"""
|
|
|
|
class MaintenanceModeMiddleware(BaseHTTPMiddleware):
|
|
async def dispatch(self, request: Request, call_next):
|
|
if maintenance_mode.value:
|
|
return HTMLResponse(
|
|
content=HTML_RESPONSE_BODY,
|
|
status_code=503
|
|
)
|
|
response = await call_next(request)
|
|
return response |