proxy-backend: let config reader check for objects

Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
This commit is contained in:
Patrik Oldsberg
2023-08-07 11:33:03 +02:00
parent 9995962c31
commit 44b1ab77e8
+2 -8
View File
@@ -192,21 +192,15 @@ export function buildMiddleware(
}
function readProxyConfig(config: Config, logger: Logger): unknown {
const endpoints = config.getOptional('proxy.endpoints');
const endpoints = config.getOptionalConfig('proxy.endpoints')?.get();
if (endpoints) {
if (typeof endpoints !== 'object' || Array.isArray(endpoints)) {
throw new Error('proxy configuration must be an object');
}
return endpoints;
}
const root = config.getOptional('proxy');
const root = config.getOptionalConfig('proxy')?.get();
if (!root) {
return {};
}
if (typeof root !== 'object' || Array.isArray(root)) {
throw new Error('deprecated proxy configuration must be an object');
}
const rootEndpoints = Object.fromEntries(
Object.entries(root).filter(([key]) => key.startsWith('/')),