[go: up one dir, main page]

Menu

[fd4e39]: / docs / uwsgi.py  Maximize  Restore  History

Download this file

33 lines (26 with data), 1.1 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
# Generated by ChatGPT-5 on October, 8, 2025.
import os
from wsgiref.util import FileWrapper
from urllib.parse import unquote
def application(environ, start_response):
"""Serve static HTML/CSS/JS files directly via uWSGI."""
root = os.path.dirname(__file__)
path = unquote(environ.get('PATH_INFO', '/'))
if path == '/' or path == '':
path = '/index.html'
full_path = os.path.join(root, path.lstrip('/'))
if not os.path.isfile(full_path):
start_response('404 Not Found', [('Content-Type', 'text/plain')])
return [b'404 Not Found']
if full_path.endswith('.html'):
content_type = 'text/html; charset=utf-8'
elif full_path.endswith('.css'):
content_type = 'text/css; charset=utf-8'
elif full_path.endswith('.js'):
content_type = 'application/javascript; charset=utf-8'
elif full_path.endswith('.svg'):
content_type = 'image/svg+xml'
else:
content_type = 'application/octet-stream'
start_response('200 OK', [('Content-Type', content_type)])
return FileWrapper(open(full_path, 'rb'))