Serve static content from memory.
This commit is contained in:
parent
708e058b01
commit
8042f5ac45
1 changed files with 8 additions and 4 deletions
12
app/main.py
12
app/main.py
|
|
@ -397,9 +397,13 @@ class Main:
|
||||||
if req.path not in self.staticHolder:
|
if req.path not in self.staticHolder:
|
||||||
return web.HTTPNotFound()
|
return web.HTTPNotFound()
|
||||||
|
|
||||||
return web.FileResponse(path=self.staticHolder[req.path].get('file'), headers={
|
item: dict = self.staticHolder[req.path]
|
||||||
'Cache-Control': 'public, max-age=31536000',
|
|
||||||
|
return web.Response(body=item.get('content'), headers={
|
||||||
'Pragma': 'public',
|
'Pragma': 'public',
|
||||||
|
'Cache-Control': 'public, max-age=31536000',
|
||||||
|
'Content-Type': item.get('content_type'),
|
||||||
|
'X-Via': 'memory' if not item.get('file', None) else 'disk',
|
||||||
})
|
})
|
||||||
|
|
||||||
staticDir = os.path.join(os.path.dirname(os.path.dirname(os.path.realpath(__file__))), 'frontend/dist')
|
staticDir = os.path.join(os.path.dirname(os.path.dirname(os.path.realpath(__file__))), 'frontend/dist')
|
||||||
|
|
@ -412,8 +416,8 @@ class Main:
|
||||||
urlPath = f"{self.config.url_prefix}{file.replace(f'{staticDir}/', '')}"
|
urlPath = f"{self.config.url_prefix}{file.replace(f'{staticDir}/', '')}"
|
||||||
|
|
||||||
self.staticHolder[urlPath] = {
|
self.staticHolder[urlPath] = {
|
||||||
'file': file,
|
# 'file': file,
|
||||||
# 'content': open(file, 'rb').read(),
|
'content': open(file, 'rb').read(),
|
||||||
'content_type': self.extToMime.get(os.path.splitext(file)[1], MIME.from_file(file)),
|
'content_type': self.extToMime.get(os.path.splitext(file)[1], MIME.from_file(file)),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue