Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: make proxy address customizable #909

Merged
merged 5 commits into from
Oct 17, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 4 additions & 9 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/oas-to-har/package.json
llimllib marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@readme/oas-to-har",
"description": "Utility to transform an OAS operation into a HAR representation",
"version": "23.2.27",
"version": "23.3.0",
"author": "Jon Ursenbach <jon@ursenba.ch>",
"license": "ISC",
"sideEffects": false,
Expand Down
11 changes: 8 additions & 3 deletions packages/oas-to-har/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -223,11 +223,16 @@ export default function oasToHar(
values: DataForHAR = {},
auth: AuthForHAR = {},
opts: oasToHarOptions = {
// If true, the operation URL will be rewritten and prefixed with https://try.readme.io/ in
// order to funnel requests through our CORS-friendly proxy.
// If true, the operation URL will be rewritten and prefixed with
// a proxy
proxyUrl: false,
},
) {
if (opts.proxyUrl && !opts.proxyAddress) {
// eslint-disable-next-line no-param-reassign
opts.proxyAddress = 'https://try.readme.io';
}

let operation: Operation;
if (!operationSchema || typeof operationSchema.getParameters !== 'function') {
/**
Expand Down Expand Up @@ -287,7 +292,7 @@ export default function oasToHar(

if (opts.proxyUrl) {
if (oas.getExtension(PROXY_ENABLED, operation)) {
har.url = `https://try.readme.io/${har.url}`;
har.url = `${opts.proxyAddress}/${har.url}`;
}
}

Expand Down
3 changes: 3 additions & 0 deletions packages/oas-to-har/src/lib/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ export type AuthForHAR = Record<string, number | string | { pass?: string; user?
export { DataForHAR } from 'oas/types';

export interface oasToHarOptions {
// The URL to use for the proxy; defaults to https://try.readme.io
proxyAddress?: string;
llimllib marked this conversation as resolved.
Show resolved Hide resolved

// If true, the operation URL will be rewritten and prefixed with https://try.readme.io/ in
// order to funnel requests through our CORS-friendly proxy.
proxyUrl: boolean;
Expand Down
11 changes: 11 additions & 0 deletions packages/oas-to-har/test/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,17 @@ describe('oas-to-har', () => {
const har = oasToHar(proxyOas, proxyOas.operation('/path', 'get'), {}, {}, { proxyUrl: true });
expect(har.log.entries[0].request.url).toBe('https://try.readme.io/https://example.com/path');
});

it('should be prefixed with beta.try.readme.io with proxyAddress option', () => {
const har = oasToHar(
proxyOas,
proxyOas.operation('/path', 'get'),
{},
{},
{ proxyUrl: true, proxyAddress: 'https://beta.try.readme.io' },
);
expect(har.log.entries[0].request.url).toBe('https://beta.try.readme.io/https://example.com/path');
});
});
});

Expand Down