@greenpress/plugins
Version:
manage plugins system
23 lines (18 loc) • 571 B
text/typescript
import {getRouter} from '@greenpress/api-kit';
import {getPlugins} from '../controllers/play-plugins';
import {createProxyMiddleware} from 'http-proxy-middleware';
import {proxyApiPrefix} from '../../config';
export async function playPlugins() {
const plugins = await getPlugins();
const router = getRouter();
plugins.forEach(plugin => {
router.use(proxyApiPrefix + '/' + plugin.apiPath, createProxyMiddleware({
target: plugin.proxyUrl,
changeOrigin: true,
headers: {
token: plugin.token,
}
}))
});
return router;
}