strongly type proxyConfig
Signed-off-by: Matt Benson <gudnabrsam@gmail.com>
This commit is contained in:
@@ -21,7 +21,6 @@ import {
|
||||
} from '@backstage/backend-plugin-api';
|
||||
import { createRouterInternal } from './service/router';
|
||||
import { proxyEndpointsExtensionPoint } from '@backstage/plugin-proxy-node/alpha';
|
||||
import { JsonObject } from '@backstage/types';
|
||||
|
||||
/**
|
||||
* The proxy backend plugin.
|
||||
@@ -34,7 +33,7 @@ export const proxyPlugin = createBackendPlugin({
|
||||
const additionalEndpoints = {};
|
||||
|
||||
env.registerExtensionPoint(proxyEndpointsExtensionPoint, {
|
||||
addProxyEndpoints(endpoints: JsonObject) {
|
||||
addProxyEndpoints(endpoints) {
|
||||
Object.assign(additionalEndpoints, endpoints);
|
||||
},
|
||||
});
|
||||
|
||||
@@ -20,7 +20,6 @@ import Router from 'express-promise-router';
|
||||
import {
|
||||
createProxyMiddleware,
|
||||
fixRequestBody,
|
||||
Options,
|
||||
RequestHandler,
|
||||
} from 'http-proxy-middleware';
|
||||
import { Logger } from 'winston';
|
||||
@@ -31,6 +30,7 @@ import {
|
||||
HttpRouterService,
|
||||
RootConfigService,
|
||||
} from '@backstage/backend-plugin-api';
|
||||
import { ProxyConfig } from '@backstage/plugin-proxy-node/alpha';
|
||||
|
||||
// A list of headers that are always forwarded to the proxy targets.
|
||||
const safeForwardHeaders = [
|
||||
@@ -66,12 +66,6 @@ export interface RouterOptions {
|
||||
additionalEndpoints?: JsonObject;
|
||||
}
|
||||
|
||||
export interface ProxyConfig extends Options {
|
||||
allowedMethods?: string[];
|
||||
allowedHeaders?: string[];
|
||||
reviveRequestBody?: boolean;
|
||||
}
|
||||
|
||||
// Creates a proxy middleware, possibly with defaults added on top of the
|
||||
// given config.
|
||||
export function buildMiddleware(
|
||||
@@ -88,7 +82,7 @@ export function buildMiddleware(
|
||||
fullConfig = { target: config };
|
||||
credentialsPolicy = 'require';
|
||||
} else {
|
||||
const { credentials, ...rest } = config as any;
|
||||
const { credentials, ...rest } = config;
|
||||
fullConfig = rest;
|
||||
credentialsPolicy = credentials ?? 'require';
|
||||
}
|
||||
|
||||
@@ -49,11 +49,12 @@
|
||||
},
|
||||
"dependencies": {
|
||||
"@backstage/backend-plugin-api": "workspace:^",
|
||||
"@backstage/types": "workspace:^"
|
||||
"http-proxy-middleware": "^2.0.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@backstage/backend-test-utils": "workspace:^",
|
||||
"@backstage/cli": "workspace:^",
|
||||
"@backstage/config": "workspace:^"
|
||||
"@backstage/config": "workspace:^",
|
||||
"@types/http-proxy-middleware": "^1.0.0"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,12 +4,24 @@
|
||||
|
||||
```ts
|
||||
import { ExtensionPoint } from '@backstage/backend-plugin-api';
|
||||
import { JsonObject } from '@backstage/types';
|
||||
import { Options } from 'http-proxy-middleware';
|
||||
|
||||
// @alpha
|
||||
export interface ProxyConfig extends Options {
|
||||
// (undocumented)
|
||||
allowedHeaders?: string[];
|
||||
// (undocumented)
|
||||
allowedMethods?: string[];
|
||||
// (undocumented)
|
||||
credentials?: 'require' | 'forward' | 'dangerously-allow-unauthenticated';
|
||||
// (undocumented)
|
||||
reviveRequestBody?: boolean;
|
||||
}
|
||||
|
||||
// @alpha
|
||||
export interface ProxyEndpointsExtensionPoint {
|
||||
// (undocumented)
|
||||
addProxyEndpoints(endpoints: JsonObject): void;
|
||||
addProxyEndpoints(endpoints: Record<string, string | ProxyConfig>): void;
|
||||
}
|
||||
|
||||
// @alpha
|
||||
|
||||
@@ -14,7 +14,19 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
import { createExtensionPoint } from '@backstage/backend-plugin-api';
|
||||
import { JsonObject } from '@backstage/types';
|
||||
import { Options } from 'http-proxy-middleware';
|
||||
|
||||
/**
|
||||
* http-proxy-middleware proxy config interface.
|
||||
*
|
||||
* @alpha
|
||||
*/
|
||||
export interface ProxyConfig extends Options {
|
||||
allowedMethods?: string[];
|
||||
allowedHeaders?: string[];
|
||||
reviveRequestBody?: boolean;
|
||||
credentials?: 'require' | 'forward' | 'dangerously-allow-unauthenticated';
|
||||
}
|
||||
|
||||
/**
|
||||
* Extension point interface for managing proxy endpoints.
|
||||
@@ -22,7 +34,7 @@ import { JsonObject } from '@backstage/types';
|
||||
* @alpha
|
||||
*/
|
||||
export interface ProxyEndpointsExtensionPoint {
|
||||
addProxyEndpoints(endpoints: JsonObject): void;
|
||||
addProxyEndpoints(endpoints: Record<string, string | ProxyConfig>): void;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -7146,7 +7146,8 @@ __metadata:
|
||||
"@backstage/backend-test-utils": "workspace:^"
|
||||
"@backstage/cli": "workspace:^"
|
||||
"@backstage/config": "workspace:^"
|
||||
"@backstage/types": "workspace:^"
|
||||
"@types/http-proxy-middleware": ^1.0.0
|
||||
http-proxy-middleware: ^2.0.0
|
||||
languageName: unknown
|
||||
linkType: soft
|
||||
|
||||
|
||||
Reference in New Issue
Block a user