Skip to content

Commit aecd817

Browse files
committed
fix: simplify the base.ts changes with config.base || '/'
1 parent 052b560 commit aecd817

1 file changed

Lines changed: 5 additions & 14 deletions

File tree

  • packages/astro/src/vite-plugin-astro-server

packages/astro/src/vite-plugin-astro-server/base.ts

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,11 @@ export function baseMiddleware(
1313
logger: Logger,
1414
): vite.Connect.NextHandleFunction {
1515
const { config } = settings;
16-
let devRoot: string;
17-
let devRootReplacement: string;
18-
let devRootURL: URL;
19-
try {
20-
const site = config.site ? new URL(config.base, config.site) : undefined;
21-
devRootURL = new URL(config.base, 'http://localhost');
22-
devRoot = site ? site.pathname : devRootURL.pathname;
23-
devRootReplacement = devRoot.endsWith('/') ? '/' : '';
24-
} catch {
25-
// If base is invalid, default to '/'
26-
devRootURL = new URL('/', 'http://localhost');
27-
devRoot = '/';
28-
devRootReplacement = '/';
29-
}
16+
const base = config.base || '/';
17+
const site = config.site ? new URL(base, config.site) : undefined;
18+
const devRootURL = new URL(base, 'http://localhost');
19+
const devRoot = site ? site.pathname : devRootURL.pathname;
20+
const devRootReplacement = devRoot.endsWith('/') ? '/' : '';
3021

3122
return function devBaseMiddleware(req, res, next) {
3223
const url = req.url!;

0 commit comments

Comments
 (0)