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

Add middleware option to override credentials prop #185

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -158,6 +158,7 @@ Middleware supports the following properties:
- `displayOptions` [`object`] - same as [here](#properties)
- `headersJS` [`string`, default `"{}"`] - object of headers serialized in string to be used on endpoint url<BR>
**Note:** You can also use any JS expression which results in an object with header names as keys and strings as values e.g. `{ Authorization: localStorage['Meteor.loginToken'] }`
- `credentials` [`string`, default `include`] - the credentials read-only property of the Request interface indicates whether the user agent should send cookies from the other domain in the case of cross-origin requests. Please refer to the [Request.credentials](https://developer.mozilla.org/en-US/docs/Web/API/Request/credentials) page for more information.

### Express

11 changes: 8 additions & 3 deletions src/middleware/render-voyager-page.ts
Original file line number Diff line number Diff line change
@@ -4,11 +4,16 @@ export interface MiddlewareOptions {
endpointUrl: string;
displayOptions?: object;
headersJS?: string;
credentials?: string;
}

export default function renderVoyagerPage(options: MiddlewareOptions) {
const { endpointUrl, displayOptions } = options;
const headersJS = options.headersJS ? options.headersJS : '{}';
const {
endpointUrl,
displayOptions,
headersJS = '{}',
credentials = 'include',
} = options;
return `
<!DOCTYPE html>
<html>
@@ -50,7 +55,7 @@ export default function renderVoyagerPage(options: MiddlewareOptions) {
'Content-Type': 'application/json',
}, ${headersJS}),
body: JSON.stringify({query: introspectionQuery }),
credentials: 'include',
credentials: '${credentials}',
}).then(function (response) {
return response.text();
}).then(function (responseBody) {