Tweak static handler path for extensions

This commit is contained in:
rijkvanzanten
2021-04-07 12:54:23 -04:00
parent 1898be9424
commit cdbd6e820b

View File

@@ -8,17 +8,20 @@ import { respond } from '../middleware/respond';
const router = Router();
const extensionsPath = env.EXTENSIONS_PATH as string;
router.use(express.static(extensionsPath));
const appExtensions = ['interfaces', 'layouts', 'displays', 'modules'];
router.get(
'/:type',
'/:type/*',
asyncHandler(async (req, res, next) => {
const typeAllowList = ['interfaces', 'layouts', 'displays', 'modules'];
if (typeAllowList.includes(req.params.type) === false) {
if (appExtensions.includes(req.params.type) === false) {
throw new RouteNotFoundException(req.path);
}
return next();
}),
express.static(extensionsPath),
asyncHandler(async (req, res, next) => {
const extensions = await listExtensions(req.params.type);
res.locals.payload = {