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:
parent
69c955b2bf
commit
47c81effa6
6 changed files with 50 additions and 1 deletions
5
.changeset/stupid-steaks-hang.md
Normal file
5
.changeset/stupid-steaks-hang.md
Normal file
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
'astro': patch
|
||||
---
|
||||
|
||||
Make Astro.redirect use a 302 status code
|
|
@ -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,
|
||||
},
|
||||
|
|
8
packages/astro/test/fixtures/ssr-redirect/package.json
vendored
Normal file
8
packages/astro/test/fixtures/ssr-redirect/package.json
vendored
Normal file
|
@ -0,0 +1,8 @@
|
|||
{
|
||||
"name": "@test/ssr-redirect",
|
||||
"version": "0.0.0",
|
||||
"private": true,
|
||||
"dependencies": {
|
||||
"astro": "workspace:*"
|
||||
}
|
||||
}
|
3
packages/astro/test/fixtures/ssr-redirect/src/pages/secret.astro
vendored
Normal file
3
packages/astro/test/fixtures/ssr-redirect/src/pages/secret.astro
vendored
Normal file
|
@ -0,0 +1,3 @@
|
|||
---
|
||||
return Astro.redirect('/login');
|
||||
---
|
27
packages/astro/test/ssr-redirect.test.js
Normal file
27
packages/astro/test/ssr-redirect.test.js
Normal 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');
|
||||
});
|
||||
});
|
|
@ -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:'
|
||||
|
|
Loading…
Reference in a new issue