mirror of
https://github.com/directus/directus.git
synced 2026-01-28 16:48:02 -05:00
57 lines
1.4 KiB
TypeScript
57 lines
1.4 KiB
TypeScript
import { Router } from 'express';
|
|
import asyncHandler from '../utils/async-handler';
|
|
import { RouteNotFoundException } from '../exceptions';
|
|
import { getExtensionManager } from '../extensions';
|
|
import { respond } from '../middleware/respond';
|
|
import { depluralize, isAppExtension } from '@directus/shared/utils';
|
|
import { Plural } from '@directus/shared/types';
|
|
|
|
const router = Router();
|
|
|
|
router.get(
|
|
'/:type',
|
|
asyncHandler(async (req, res, next) => {
|
|
const type = depluralize(req.params.type as Plural<string>);
|
|
|
|
if (!isAppExtension(type)) {
|
|
throw new RouteNotFoundException(req.path);
|
|
}
|
|
|
|
const extensionManager = getExtensionManager();
|
|
|
|
const extensions = extensionManager.listExtensions(type);
|
|
|
|
res.locals.payload = {
|
|
data: extensions,
|
|
};
|
|
|
|
return next();
|
|
}),
|
|
respond
|
|
);
|
|
|
|
router.get(
|
|
'/:type/index.js',
|
|
asyncHandler(async (req, res) => {
|
|
const type = depluralize(req.params.type as Plural<string>);
|
|
|
|
if (!isAppExtension(type)) {
|
|
throw new RouteNotFoundException(req.path);
|
|
}
|
|
|
|
const extensionManager = getExtensionManager();
|
|
|
|
const extensionSource = extensionManager.getAppExtensions(type);
|
|
if (extensionSource === undefined) {
|
|
throw new RouteNotFoundException(req.path);
|
|
}
|
|
|
|
res.setHeader('Content-Type', 'application/javascript; charset=UTF-8');
|
|
res.setHeader('Cache-Control', 'no-cache');
|
|
res.setHeader('Vary', 'Origin, Cache-Control');
|
|
res.end(extensionSource);
|
|
})
|
|
);
|
|
|
|
export default router;
|