API - fix serving images

This commit is contained in:
Sam 2022-02-13 10:21:22 +01:00
parent f3e0f5e4b7
commit 4a911be085

View File

@ -3,7 +3,13 @@ import os
from importlib import import_module, reload from importlib import import_module, reload
from typing import Any from typing import Any
from flask import Flask, Response, render_template, send_file from flask import (
Flask,
Response,
render_template,
send_file,
send_from_directory,
)
from flask_bcrypt import Bcrypt from flask_bcrypt import Bcrypt
from flask_dramatiq import Dramatiq from flask_dramatiq import Dramatiq
from flask_migrate import Migrate from flask_migrate import Migrate
@ -112,12 +118,12 @@ def create_app() -> Flask:
def catch_all(path: str) -> Any: def catch_all(path: str) -> Any:
# workaround to serve images (not in static directory) # workaround to serve images (not in static directory)
if path.startswith('img/'): if path.startswith('img/'):
return send_file( return send_from_directory(
os.path.join( directory=os.path.join(
app.root_path, # type: ignore app.root_path, # type: ignore
'dist', 'dist',
path, ),
) path=path,
) )
else: else:
return render_template('index.html') return render_template('index.html')