Skip to content

Commit 7cb7189

Browse files
ematipicoastrobot-houston
authored andcommitted
[ci] format
1 parent 32fafeb commit 7cb7189

File tree

2 files changed

+48
-43
lines changed

2 files changed

+48
-43
lines changed

packages/astro/src/core/routing/rewrite.ts

+8-5
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,12 @@ import { shouldAppendForwardSlash } from '../build/util.js';
55
import { originPathnameSymbol } from '../constants.js';
66
import { AstroError, AstroErrorData } from '../errors/index.js';
77
import type { Logger } from '../logger/core.js';
8-
import { appendForwardSlash, removeTrailingForwardSlash, joinPaths, prependForwardSlash } from '../path.js';
8+
import {
9+
appendForwardSlash,
10+
joinPaths,
11+
prependForwardSlash,
12+
removeTrailingForwardSlash,
13+
} from '../path.js';
914
import { createRequest } from '../request.js';
1015
import { DEFAULT_404_ROUTE } from './astro-designed-error-pages.js';
1116

@@ -24,7 +29,6 @@ export interface FindRouteToRewriteResult {
2429
pathname: string;
2530
}
2631

27-
2832
/**
2933
* Shared logic to retrieve the rewritten route. It returns a tuple that represents:
3034
* 1. The new `Request` object. It contains `base`
@@ -60,13 +64,13 @@ export function findRouteToRewrite({
6064

6165
if (!pathname.startsWith('/') && shouldAppendSlash && newUrl.pathname.endsWith('/')) {
6266
// when base is in the rewrite call and trailingSlash is 'always' this is needed or it will 404.
63-
pathname = prependForwardSlash(pathname)
67+
pathname = prependForwardSlash(pathname);
6468
}
6569

6670
if (pathname === '/' && base !== '/' && !shouldAppendSlash) {
6771
// when rewriting to index and trailingSlash is 'never' this is needed or it will 404
6872
// in this case the pattern will look for '/^$/' so '/' will never match
69-
pathname = ''
73+
pathname = '';
7074
}
7175

7276
newUrl.pathname = joinPaths(...[base, pathname].filter(Boolean));
@@ -151,4 +155,3 @@ export function getOriginPathname(request: Request): string {
151155
}
152156
return new URL(request.url).pathname;
153157
}
154-

packages/astro/test/rewrite.test.js

+40-38
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,6 @@ describe('Dev rewrite, trailing slash -> never, with base', () => {
103103
await devServer.stop();
104104
});
105105

106-
107106
it('should rewrite to the homepage', async () => {
108107
const html = await fixture.fetch('/base/foo').then((res) => res.text());
109108
const $ = cheerioLoad(html);
@@ -208,7 +207,7 @@ describe('Dev rewrite URL contains base and has no trailing slash', () => {
208207
before(async () => {
209208
fixture = await loadFixture({
210209
root: './fixtures/rewrite-with-base/',
211-
trailingSlash: 'never'
210+
trailingSlash: 'never',
212211
});
213212
devServer = await fixture.startDevServer();
214213
});
@@ -217,40 +216,40 @@ describe('Dev rewrite URL contains base and has no trailing slash', () => {
217216
await devServer.stop();
218217
});
219218

220-
it("should rewrite to homepage & url contains base", async () => {
221-
const html = await fixture.fetch('/base/rewrite-to-index').then(res => res.text())
222-
const $ = cheerioLoad(html)
219+
it('should rewrite to homepage & url contains base', async () => {
220+
const html = await fixture.fetch('/base/rewrite-to-index').then((res) => res.text());
221+
const $ = cheerioLoad(html);
223222

224223
assert.equal($('h1').text(), 'Index');
225224
assert.equal($('p').text(), '/base');
226-
})
225+
});
227226

228-
it("should rewrite to homepage & url contains base when base is in the rewrite call", async () => {
229-
const html = await fixture.fetch('/base/rewrite-with-base-to-index').then(res => res.text())
230-
const $ = cheerioLoad(html)
227+
it('should rewrite to homepage & url contains base when base is in the rewrite call', async () => {
228+
const html = await fixture.fetch('/base/rewrite-with-base-to-index').then((res) => res.text());
229+
const $ = cheerioLoad(html);
231230

232231
assert.equal($('h1').text(), 'Index');
233232
assert.equal($('p').text(), '/base');
234-
})
233+
});
235234

236-
it("should rewrite to subpage & url contains base", async () => {
237-
const html = await fixture.fetch('/base/rewrite-to-subpage').then(res => res.text())
238-
const $ = cheerioLoad(html)
235+
it('should rewrite to subpage & url contains base', async () => {
236+
const html = await fixture.fetch('/base/rewrite-to-subpage').then((res) => res.text());
237+
const $ = cheerioLoad(html);
239238

240239
assert.equal($('h1').text(), 'Page');
241240
assert.equal($('p').text(), '/base/page');
242-
})
243-
241+
});
244242

245-
it("should rewrite to page & url contains base when base is in the rewrite call", async () => {
246-
const html = await fixture.fetch('/base/rewrite-with-base-to-subpage').then(res => res.text())
247-
const $ = cheerioLoad(html)
243+
it('should rewrite to page & url contains base when base is in the rewrite call', async () => {
244+
const html = await fixture
245+
.fetch('/base/rewrite-with-base-to-subpage')
246+
.then((res) => res.text());
247+
const $ = cheerioLoad(html);
248248

249249
assert.equal($('h1').text(), 'Page');
250250
assert.equal($('p').text(), '/base/page');
251-
})
252-
253-
})
251+
});
252+
});
254253
describe('Dev rewrite URL contains base and has trailing slash', () => {
255254
/** @type {import('./test-utils').Fixture} */
256255
let fixture;
@@ -259,7 +258,7 @@ describe('Dev rewrite URL contains base and has trailing slash', () => {
259258
before(async () => {
260259
fixture = await loadFixture({
261260
root: './fixtures/rewrite-with-base/',
262-
trailingSlash: 'always'
261+
trailingSlash: 'always',
263262
});
264263
devServer = await fixture.startDevServer();
265264
});
@@ -268,33 +267,36 @@ describe('Dev rewrite URL contains base and has trailing slash', () => {
268267
await devServer.stop();
269268
});
270269

271-
it("should rewrite to homepage & url contains base when base is in the rewrite call", async () => {
272-
const html = await fixture.fetch('/base/rewrite-with-base-to-index-with-slash/').then(res => res.text())
273-
const $ = cheerioLoad(html)
270+
it('should rewrite to homepage & url contains base when base is in the rewrite call', async () => {
271+
const html = await fixture
272+
.fetch('/base/rewrite-with-base-to-index-with-slash/')
273+
.then((res) => res.text());
274+
const $ = cheerioLoad(html);
274275

275276
assert.equal($('h1').text(), 'Index');
276277
assert.equal($('p').text(), '/base/');
277-
})
278+
});
278279

279-
it("should rewrite to subpage & url contains base", async () => {
280-
const html = await fixture.fetch('/base/rewrite-to-subpage-with-slash/').then(res => res.text())
281-
const $ = cheerioLoad(html)
280+
it('should rewrite to subpage & url contains base', async () => {
281+
const html = await fixture
282+
.fetch('/base/rewrite-to-subpage-with-slash/')
283+
.then((res) => res.text());
284+
const $ = cheerioLoad(html);
282285

283286
assert.equal($('h1').text(), 'Page');
284287
assert.equal($('p').text(), '/base/page/');
285-
})
286-
288+
});
287289

288-
it("should rewrite to page & url contains base when base is in the rewrite call", async () => {
289-
const html = await fixture.fetch('/base/rewrite-with-base-to-subpage-with-slash/').then(res => res.text())
290-
const $ = cheerioLoad(html)
290+
it('should rewrite to page & url contains base when base is in the rewrite call', async () => {
291+
const html = await fixture
292+
.fetch('/base/rewrite-with-base-to-subpage-with-slash/')
293+
.then((res) => res.text());
294+
const $ = cheerioLoad(html);
291295

292296
assert.equal($('h1').text(), 'Page');
293297
assert.equal($('p').text(), '/base/page/');
294-
})
295-
296-
})
297-
298+
});
299+
});
298300

299301
describe('Build reroute', () => {
300302
/** @type {import('./test-utils').Fixture} */

0 commit comments

Comments
 (0)