0
Fork 0
mirror of https://github.com/withastro/astro.git synced 2024-12-23 21:53:55 -05:00

Make Astro.redirect use a 302 status code (#3700)

* Make Astro.redirect use a 302 status code

* Adds a changeset

* Add a package.json
This commit is contained in:
Matthew Phillips 2022-06-24 15:55:06 -04:00 committed by GitHub
parent 69c955b2bf
commit 47c81effa6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 50 additions and 1 deletions

View file

@ -0,0 +1,5 @@
---
'astro': patch
---
Make Astro.redirect use a 302 status code

View file

@ -152,7 +152,7 @@ export function createResult(args: CreateResultArgs): SSRResult {
redirect: args.ssr
? (path: string) => {
return new Response(null, {
status: 301,
status: 302,
headers: {
Location: path,
},

View file

@ -0,0 +1,8 @@
{
"name": "@test/ssr-redirect",
"version": "0.0.0",
"private": true,
"dependencies": {
"astro": "workspace:*"
}
}

View file

@ -0,0 +1,3 @@
---
return Astro.redirect('/login');
---

View file

@ -0,0 +1,27 @@
import { expect } from 'chai';
import { loadFixture } from './test-utils.js';
import testAdapter from './test-adapter.js';
describe('Astro.redirect', () => {
/** @type {import('./test-utils').Fixture} */
let fixture;
before(async () => {
fixture = await loadFixture({
root: './fixtures/ssr-redirect/',
experimental: {
ssr: true,
},
adapter: testAdapter(),
});
await fixture.build();
});
it('Returns a 302 status', async () => {
const app = await fixture.loadTestAdapterApp();
const request = new Request('http://example.com/secret');
const response = await app.render(request);
expect(response.status).to.equal(302);
expect(response.headers.get('location')).to.equal('/login');
});
});

View file

@ -1636,6 +1636,12 @@ importers:
'@astrojs/partytown': link:../../../../integrations/partytown
astro: link:../../..
packages/astro/test/fixtures/ssr-redirect:
specifiers:
astro: workspace:*
dependencies:
astro: link:../../..
packages/astro/test/fixtures/ssr-scripts:
specifiers:
'@astrojs/preact': 'workspace:'