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

@@ -0,0 +1,6 @@
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"
aria-label="Slack" role="img"
viewBox="0 0 512 512"><rect
width="512" height="512"
rx="15%"
fill="#fff"/><g fill="#e01e5a"><path id="a" d="M149 305a39 39 0 01-78 0c0-22 17 -39 39 -39h39zM168 305a39 39 0 0178 0v97a39 39 0 01-78 0z"/></g><use xlink:href="#a" fill="#36c5f0" transform="rotate(90,256,256)"/><use xlink:href="#a" fill="#2eb67d" transform="rotate(180,256,256)"/><use xlink:href="#a" fill="#ecb22e" transform="rotate(270,256,256)"/></svg>

After

Width:  |  Height:  |  Size: 531 B

View File

@@ -0,0 +1,4 @@
<svg xmlns="http://www.w3.org/2000/svg" aria-label="Twitter" role="img" viewBox="0 0 512 512">
<rect width="512" height="512" rx="15%" fill="#1da1f2"/>
<path fill="#fff" d="M437 152a72 72 0 01-40 12a72 72 0 0032-40a72 72 0 01-45 17a72 72 0 00-122 65a200 200 0 01-145-74a72 72 0 0022 94a72 72 0 01-32-7a72 72 0 0056 69a72 72 0 01-32 1a72 72 0 0067 50a200 200 0 01-105 29a200 200 0 00309-179a200 200 0 0035-37"/>
</svg>

After

Width:  |  Height:  |  Size: 421 B

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);
});
};