Pull in custom interfaces from the API

This commit is contained in:
rijkvanzanten
2020-09-15 18:33:08 -04:00
parent b8eff4c788
commit 5f4b97aeab
5 changed files with 61 additions and 37 deletions

View File

@@ -1,27 +1,32 @@
import { Router } from 'express';
import express, { Router } from 'express';
import asyncHandler from 'express-async-handler';
import * as ExtensionsService from '../services/extensions';
import { RouteNotFoundException } from '../exceptions';
import ExtensionsService from '../services/extensions';
import env from '../env';
const router = Router();
const extensionsPath = env.EXTENSIONS_PATH as string;
router.use(express.static(extensionsPath));
router.get(
'/:type',
asyncHandler(async (req, res, next) => {
const service = new ExtensionsService();
const typeAllowList = ['interfaces', 'layouts', 'displays', 'modules'];
if (typeAllowList.includes(req.params.type) === false) {
throw new RouteNotFoundException(req.path);
}
const interfaces = await ExtensionsService.listExtensions(req.params.type);
const extensions = await service.listExtensions(req.params.type);
res.locals.payload = {
data: interfaces,
data: extensions,
};
return next();
}),
})
);
export default router;