mirror of
https://github.com/Unleash/unleash.git
synced 2024-12-22 19:07:54 +01:00
If baseUriPath is set format it, but if it's not, don't override default with empty string (#2118)
From Thomas and mine testing. BaseUriPath can't be set as an environment variable because we override it when trying to format the URI from the server config. This PR makes sure we only format if the custom server options actually have baseUriPath set. Co-authored-by: Thomas Heartman <thomas@getunleash.ai>
This commit is contained in:
parent
d5e33ab1f2
commit
5b3d95cc3a
@ -428,3 +428,37 @@ test('Environment variables for frontend CORS origins takes priority over option
|
||||
delete process.env.UNLEASH_FRONTEND_API_ORIGINS;
|
||||
expect(create()).toEqual(['*']);
|
||||
});
|
||||
|
||||
test('baseUriPath defaults to the empty string', async () => {
|
||||
let config = createConfig({});
|
||||
expect(config.server.baseUriPath).toBe('');
|
||||
});
|
||||
test('BASE_URI_PATH defined in env is passed through', async () => {
|
||||
process.env.BASE_URI_PATH = '/demo';
|
||||
let config = createConfig({});
|
||||
expect(config.server.baseUriPath).toBe('/demo');
|
||||
delete process.env.BASE_URI_PATH;
|
||||
});
|
||||
|
||||
test('environment variable takes precedence over configured variable', async () => {
|
||||
process.env.BASE_URI_PATH = '/demo';
|
||||
let config = createConfig({
|
||||
server: {
|
||||
baseUriPath: '/other',
|
||||
},
|
||||
});
|
||||
expect(config.server.baseUriPath).toBe('/demo');
|
||||
delete process.env.BASE_URI_PATH;
|
||||
});
|
||||
|
||||
test.each(['demo', '/demo', '/demo/'])(
|
||||
'Trailing and leading slashes gets normalized for base path %s',
|
||||
async (path) => {
|
||||
let config = createConfig({
|
||||
server: {
|
||||
baseUriPath: path,
|
||||
},
|
||||
});
|
||||
expect(config.server.baseUriPath).toBe('/demo');
|
||||
},
|
||||
);
|
||||
|
@ -231,12 +231,18 @@ const removeUndefinedKeys = (o: object): object =>
|
||||
const formatServerOptions = (
|
||||
serverOptions?: Partial<IServerOption>,
|
||||
): Partial<IServerOption> | undefined => {
|
||||
if (!serverOptions) return;
|
||||
if (!serverOptions) {
|
||||
return {
|
||||
baseUriPath: formatBaseUri(process.env.BASE_URI_PATH),
|
||||
};
|
||||
}
|
||||
|
||||
/* eslint-disable-next-line */
|
||||
return {
|
||||
...serverOptions,
|
||||
baseUriPath: formatBaseUri(serverOptions.baseUriPath),
|
||||
baseUriPath: formatBaseUri(
|
||||
process.env.BASE_URI_PATH || serverOptions.baseUriPath,
|
||||
),
|
||||
};
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user