Fix serving static files. Fixes #206
This commit is contained in:
parent
719c9c5dd0
commit
c9282b93f4
1 changed files with 8 additions and 3 deletions
|
@ -127,6 +127,13 @@ class MaubotServer:
|
||||||
)
|
)
|
||||||
self.app.router.add_get(ui_base, ui_base_redirect)
|
self.app.router.add_get(ui_base, ui_base_redirect)
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def _static_data(data: bytes, mime: str) -> Callable[[web.Request], web.Response]:
|
||||||
|
def fn(_: web.Request) -> web.Response:
|
||||||
|
return web.Response(body=data, content_type=mime)
|
||||||
|
|
||||||
|
return fn
|
||||||
|
|
||||||
def setup_static_root_files(self, directory: str, ui_base: str) -> None:
|
def setup_static_root_files(self, directory: str, ui_base: str) -> None:
|
||||||
files = {
|
files = {
|
||||||
"asset-manifest.json": "application/json",
|
"asset-manifest.json": "application/json",
|
||||||
|
@ -136,9 +143,7 @@ class MaubotServer:
|
||||||
for file, mime in files.items():
|
for file, mime in files.items():
|
||||||
with open(f"{directory}/{file}", "rb") as stream:
|
with open(f"{directory}/{file}", "rb") as stream:
|
||||||
data = stream.read()
|
data = stream.read()
|
||||||
self.app.router.add_get(
|
self.app.router.add_get(f"{ui_base}/{file}", self._static_data(data, mime))
|
||||||
f"{ui_base}/{file}", lambda _: web.Response(body=data, content_type=mime)
|
|
||||||
)
|
|
||||||
|
|
||||||
public_url = self.config["server.public_url"]
|
public_url = self.config["server.public_url"]
|
||||||
public_url_path = ""
|
public_url_path = ""
|
||||||
|
|
Loading…
Reference in a new issue