fix build base bug (#3068)
* fix ssr url search params bug * fix build base bug * safer slash removal
This commit is contained in:
parent
564caf24c2
commit
81e210e03c
5 changed files with 19 additions and 11 deletions
5
.changeset/nice-dingos-enjoy.md
Normal file
5
.changeset/nice-dingos-enjoy.md
Normal file
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
'astro': patch
|
||||
---
|
||||
|
||||
Fix an issue around build not respecting your base config
|
|
@ -11,7 +11,7 @@ import type {
|
|||
} from '../../@types/astro';
|
||||
import type { BuildInternals } from '../../core/build/internal.js';
|
||||
import { debug, info } from '../logger/core.js';
|
||||
import { prependForwardSlash } from '../../core/path.js';
|
||||
import { prependForwardSlash, removeLeadingForwardSlash } from '../../core/path.js';
|
||||
import type { RenderOptions } from '../../core/render/core';
|
||||
import { BEFORE_HYDRATION_SCRIPT_ID } from '../../vite-plugin-scripts/index.js';
|
||||
import { call as callEndpoint } from '../endpoint/index.js';
|
||||
|
@ -191,7 +191,7 @@ async function generatePath(
|
|||
}
|
||||
|
||||
const ssr = isBuildingToSSR(opts.astroConfig);
|
||||
const url = new URL(origin + pathname);
|
||||
const url = new URL(opts.astroConfig.base + removeLeadingForwardSlash(pathname), origin);
|
||||
const options: RenderOptions = {
|
||||
legacyBuild: false,
|
||||
links,
|
||||
|
|
|
@ -6,10 +6,18 @@ export function prependForwardSlash(path: string) {
|
|||
return path[0] === '/' ? path : '/' + path;
|
||||
}
|
||||
|
||||
export function removeEndingForwardSlash(path: string) {
|
||||
export function removeTrailingForwardSlash(path: string) {
|
||||
return path.endsWith('/') ? path.slice(0, path.length - 1) : path;
|
||||
}
|
||||
|
||||
export function removeLeadingForwardSlash(path: string) {
|
||||
return path.startsWith('/') ? path.substring(1) : path;
|
||||
}
|
||||
|
||||
export function trimSlashes(path: string) {
|
||||
return path.replace(/^\/|\/$/g, '');
|
||||
}
|
||||
|
||||
export function startsWithForwardSlash(path: string) {
|
||||
return path[0] === '/';
|
||||
}
|
||||
|
@ -39,6 +47,3 @@ export function prependDotSlash(path: string) {
|
|||
return './' + path;
|
||||
}
|
||||
|
||||
export function trimSlashes(path: string) {
|
||||
return path.replace(/^\/|\/$/g, '');
|
||||
}
|
||||
|
|
|
@ -6,7 +6,7 @@ import slash from 'slash';
|
|||
import { fileURLToPath, pathToFileURL } from 'url';
|
||||
import type { ErrorPayload } from 'vite';
|
||||
import type { AstroConfig } from '../@types/astro';
|
||||
import { removeEndingForwardSlash } from './path.js';
|
||||
import { removeTrailingForwardSlash } from './path.js';
|
||||
|
||||
/** Returns true if argument is an object of any prototype/class (but not null). */
|
||||
export function isObject(value: unknown): value is Record<string, any> {
|
||||
|
@ -37,7 +37,7 @@ export function getOutputFilename(astroConfig: AstroConfig, name: string) {
|
|||
if (astroConfig.build.format === 'directory' && !STATUS_CODE_REGEXP.test(name)) {
|
||||
return path.posix.join(name, 'index.html');
|
||||
}
|
||||
return `${removeEndingForwardSlash(name || 'index')}.html`;
|
||||
return `${removeTrailingForwardSlash(name || 'index')}.html`;
|
||||
}
|
||||
|
||||
/** is a specifier an npm package? */
|
||||
|
|
|
@ -38,9 +38,7 @@ describe('Astro.*', () => {
|
|||
await fixture.build();
|
||||
});
|
||||
|
||||
// BUG: Doesn't seem like `base` config is being respected in build,
|
||||
// most values are incorrect actual, does not match expected.
|
||||
it.skip('Astro.request.url', async () => {
|
||||
it('Astro.request.url', async () => {
|
||||
const html = await fixture.readFile('/index.html');
|
||||
const $ = cheerio.load(html);
|
||||
|
||||
|
|
Loading…
Reference in a new issue