only skip proxies if configured to do so

Signed-off-by: Brian Fletcher <brian@roadie.io>
This commit is contained in:
Brian Fletcher
2022-01-28 11:28:14 +00:00
parent 332d3decb2
commit 8030dc7dd5
2 changed files with 37 additions and 2 deletions
@@ -60,7 +60,36 @@ describe('createRouter', () => {
});
describe('where buildMiddleware would fail', () => {
it('works', async () => {
it('throws an error if skip failures is not set', async () => {
const logger = getVoidLogger();
logger.warn = jest.fn();
const config = new ConfigReader({
backend: {
baseUrl: 'https://example.com:7007',
listen: {
port: 7007,
},
},
// no target would cause the buildMiddleware to fail
proxy: {
'/test': {
headers: {
Authorization: 'Bearer supersecret',
},
},
},
});
const discovery = SingleHostDiscovery.fromConfig(config);
await expect(
createRouter({
config,
logger,
discovery,
}),
).rejects.toThrow(new Error('Proxy target must be a string'));
});
it('works if skip failures is set', async () => {
const logger = getVoidLogger();
logger.warn = jest.fn();
const config = new ConfigReader({
@@ -84,6 +113,7 @@ describe('createRouter', () => {
config,
logger,
discovery,
skipBrokenProxies: true,
});
expect((logger.warn as jest.Mock).mock.calls[0][0]).toEqual(
'skipped configuring /test due to Proxy target must be a string',
+6 -1
View File
@@ -51,6 +51,7 @@ export interface RouterOptions {
logger: Logger;
config: Config;
discovery: PluginEndpointDiscovery;
skipBrokenProxies?: boolean;
}
export interface ProxyConfig extends Options {
@@ -193,7 +194,11 @@ export async function createRouter(
buildMiddleware(pathPrefix, options.logger, route, proxyRouteConfig),
);
} catch (e) {
options.logger.warn(`skipped configuring ${route} due to ${e.message}`);
if (options.skipBrokenProxies) {
options.logger.warn(`skipped configuring ${route} due to ${e.message}`);
} else {
throw e;
}
}
});