fix: serve assets synchronously

This commit is contained in:
Ali BARIN
2022-10-06 18:33:50 +02:00
committed by Faruk AYDIN
parent ae76f7100c
commit 5037e67857
3 changed files with 14 additions and 6 deletions

View File

@@ -1,11 +1,9 @@
import express, { Application } from 'express';
import App from '../models/app';
const appAssetsHandler = async (app: Application) => {
const appList = await App.findAll();
appList.forEach((appItem) => {
const svgPath = `${__dirname}/../apps/${appItem.name}/assets/favicon.svg`;
app.use('/apps/:appKey/assets/favicon.svg', (req, res, next) => {
const { appKey } = req.params;
const svgPath = `${__dirname}/../apps/${appKey}/assets/favicon.svg`;
const staticFileHandlerOptions = {
/**
* Disabling fallthrough is important to respond with HTTP 404.
@@ -15,7 +13,7 @@ const appAssetsHandler = async (app: Application) => {
};
const staticFileHandler = express.static(svgPath, staticFileHandlerOptions);
app.use(`/apps/${appItem.name}/assets/favicon.svg`, staticFileHandler);
return staticFileHandler(req, res, next);
});
};