Skip to content

Commit

Permalink
feat: supports status for redirects
Browse files Browse the repository at this point in the history
  • Loading branch information
dzucconi committed Jul 24, 2020
1 parent 78de701 commit 0ece0b7
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ export async function getFarceResult({
// The store is not exposed to the user, so we need to build the redirect
// URL here.
return {
status: e.status || 302,
redirect: {
url: store.farce.createHref(e.location),
},
Expand Down
26 changes: 26 additions & 0 deletions test/server/getFarceResult.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,32 @@ describe('getFarceResult', () => {
"redirect": Object {
"url": "/bar",
},
"status": 302,
}
`);
});

it('should support redirect with custom status codes', async () => {
expect(
await getFarceResult({
url: '/foo',
routeConfig: [
{
path: 'foo',
render: () => {
const err = new RedirectException('/bar');
err.status = 301;
throw err;
},
},
],
}),
).toMatchInlineSnapshot(`
Object {
"redirect": Object {
"url": "/bar",
},
"status": 301,
}
`);
});
Expand Down

0 comments on commit 0ece0b7

Please sign in to comment.