Skip to content

Commit

Permalink
Add location parameter to REDIRECT
Browse files Browse the repository at this point in the history
Fixes #22
  • Loading branch information
mbungalso committed Mar 3, 2021
1 parent c14773a commit 90502c0
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 8 deletions.
2 changes: 1 addition & 1 deletion 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 package.json
Original file line number Diff line number Diff line change
Expand Up @@ -92,4 +92,4 @@
"pretty-quick --staged"
]
}
}
}
5 changes: 2 additions & 3 deletions src/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,8 @@ export interface OpsInput {

export interface OpsRedirectInput {
cors?: boolean;
headers: {
Location: string;
};
location: string;
headers?: object;
permanent: boolean;
}

Expand Down
5 changes: 4 additions & 1 deletion src/success.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,12 @@ export const CREATED = (opts: OpsInput): BuildOutput =>
buildResponse({ statusCode: STATUS.CREATED, ...opts });
export const NO_CONTENT = (opts?: OpsInput): BuildOutput =>
buildResponse({ statusCode: STATUS.NO_CONTENT, ...opts, body: null });
export const REDIRECT = ({ permanent, ...opts }: OpsRedirectInput) =>
export const REDIRECT = ({ permanent, location, ...opts }: OpsRedirectInput) =>
buildResponse({
statusCode: permanent ? STATUS.REDIRECT_PERM : STATUS.REDIRECT_TEMP,
...opts,
headers: {
Location: location,
},
body: null,
});
4 changes: 2 additions & 2 deletions tests/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,7 @@ describe('Build response', () => {
test('REDIRECT Permanent', async () => {
const resp = response.REDIRECT({
permanent: true,
headers: { Location: 'https://www.kdcsoftware.com' },
location: 'https://www.kdcsoftware.com',
});

expect(resp).toEqual({
Expand All @@ -454,7 +454,7 @@ describe('Build response', () => {
test('REDIRECT Temporary', async () => {
const resp = response.REDIRECT({
permanent: false,
headers: { Location: 'https://www.kdcsoftware.com' },
location: 'https://www.kdcsoftware.com',
});

expect(resp).toEqual({
Expand Down

0 comments on commit 90502c0

Please sign in to comment.