Skip to content

Commit

Permalink
[ci] format
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewp authored and astrobot-houston committed Jun 9, 2023
1 parent bbcf69e commit 5c20476
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 14 deletions.
6 changes: 5 additions & 1 deletion packages/astro/src/core/endpoint/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,11 @@ function isRedirect(statusCode: number) {
}

export function throwIfRedirectNotAllowed(response: Response, config: AstroConfig) {
if (!isServerLikeOutput(config) && isRedirect(response.status) && !config.experimental.redirects) {
if (
!isServerLikeOutput(config) &&
isRedirect(response.status) &&
!config.experimental.redirects
) {
throw new AstroError(AstroErrorData.StaticRedirectNotAvailable);
}
}
12 changes: 8 additions & 4 deletions packages/astro/src/prerender/routing.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import type { AstroSettings, RouteData } from '../@types/astro';
import { preload, type DevelopmentEnvironment, type ComponentPreload } from '../core/render/dev/index.js';
import { RedirectComponentInstance, routeIsRedirect } from '../core/redirects/index.js';
import {
preload,
type ComponentPreload,
type DevelopmentEnvironment,
} from '../core/render/dev/index.js';
import { getPrerenderStatus } from './metadata.js';
import { routeIsRedirect, RedirectComponentInstance } from '../core/redirects/index.js';

type GetSortedPreloadedMatchesParams = {
env: DevelopmentEnvironment;
Expand Down Expand Up @@ -43,12 +47,12 @@ async function preloadAndSetPrerenderStatus({
matches.map(async (route) => {
const filePath = new URL(`./${route.component}`, settings.config.root);

if(routeIsRedirect(route)) {
if (routeIsRedirect(route)) {
const preloadedComponent: ComponentPreload = [[], RedirectComponentInstance];
return {
preloadedComponent,
route,
filePath
filePath,
};
}

Expand Down
18 changes: 9 additions & 9 deletions packages/astro/test/redirects.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,37 +86,37 @@ describe('Astro.redirect', () => {
});
await fixture.build();
});

it('Includes the meta refresh tag in Astro.redirect pages', async () => {
const html = await fixture.readFile('/secret/index.html');
expect(html).to.include('http-equiv="refresh');
expect(html).to.include('url=/login');
});

it('Includes the meta refresh tag in `redirect` config pages', async () => {
let html = await fixture.readFile('/one/index.html');
expect(html).to.include('http-equiv="refresh');
expect(html).to.include('url=/');

html = await fixture.readFile('/two/index.html');
expect(html).to.include('http-equiv="refresh');
expect(html).to.include('url=/');

html = await fixture.readFile('/three/index.html');
expect(html).to.include('http-equiv="refresh');
expect(html).to.include('url=/');
});

it('Generates page for dynamic routes', async () => {
let html = await fixture.readFile('/blog/one/index.html');
expect(html).to.include('http-equiv="refresh');
expect(html).to.include('url=/articles/one');

html = await fixture.readFile('/blog/two/index.html');
expect(html).to.include('http-equiv="refresh');
expect(html).to.include('url=/articles/two');
});

it('Generates redirect pages for redirects created by middleware', async () => {
let html = await fixture.readFile('/middleware-redirect/index.html');
expect(html).to.include('http-equiv="refresh');
Expand Down Expand Up @@ -145,10 +145,10 @@ describe('Astro.redirect', () => {
after(async () => {
await devServer.stop();
});

it('Returns 301', async () => {
let res = await fixture.fetch('/one', {
redirect: 'manual'
redirect: 'manual',
});
expect(res.status).to.equal(301);
});
Expand Down

0 comments on commit 5c20476

Please sign in to comment.