chore: Refactor a little bit to use proxyconfig instead
Signed-off-by: blam <ben@blam.sh>
This commit is contained in:
@@ -6,8 +6,8 @@
|
||||
import { BackendFeature } from '@backstage/backend-plugin-api';
|
||||
import { DiscoveryService } from '@backstage/backend-plugin-api';
|
||||
import express from 'express';
|
||||
import { JsonObject } from '@backstage/types';
|
||||
import { Logger } from 'winston';
|
||||
import { ProxyConfig } from '@backstage/plugin-proxy-node/alpha';
|
||||
import { RootConfigService } from '@backstage/backend-plugin-api';
|
||||
|
||||
// @public @deprecated
|
||||
@@ -20,7 +20,7 @@ export default proxyPlugin;
|
||||
// @public @deprecated (undocumented)
|
||||
export interface RouterOptions {
|
||||
// (undocumented)
|
||||
additionalEndpoints?: JsonObject;
|
||||
additionalEndpoints?: ProxyConfig;
|
||||
// (undocumented)
|
||||
config: RootConfigService;
|
||||
// (undocumented)
|
||||
|
||||
@@ -63,7 +63,7 @@ export interface RouterOptions {
|
||||
discovery: DiscoveryService;
|
||||
skipInvalidProxies?: boolean;
|
||||
reviveConsumedRequestBodies?: boolean;
|
||||
additionalEndpoints?: JsonObject;
|
||||
additionalEndpoints?: ProxyConfig;
|
||||
}
|
||||
|
||||
// Creates a proxy middleware, possibly with defaults added on top of the
|
||||
@@ -310,10 +310,11 @@ export async function createRouterInternal(
|
||||
const externalUrl = await options.discovery.getExternalBaseUrl('proxy');
|
||||
const { pathname: pathPrefix } = new URL(externalUrl);
|
||||
|
||||
const proxyConfig = {
|
||||
const proxyConfig: ProxyConfig = {
|
||||
...(options.additionalEndpoints ?? {}),
|
||||
...readProxyConfig(options.config, options.logger),
|
||||
};
|
||||
|
||||
configureMiddlewares(
|
||||
proxyOptions,
|
||||
currentRouter,
|
||||
@@ -356,10 +357,10 @@ function configureMiddlewares(
|
||||
},
|
||||
router: express.Router,
|
||||
pathPrefix: string,
|
||||
proxyConfig: any,
|
||||
proxyConfig: ProxyConfig,
|
||||
httpRouterService?: HttpRouterService,
|
||||
) {
|
||||
Object.entries<any>(proxyConfig).forEach(([route, proxyRouteConfig]) => {
|
||||
Object.entries(proxyConfig).forEach(([route, proxyRouteConfig]) => {
|
||||
try {
|
||||
router.use(
|
||||
route,
|
||||
|
||||
Reference in New Issue
Block a user