mirror of
https://github.com/withastro/astro.git
synced 2024-12-30 22:03:56 -05:00
improve preview reliability - fix broken tests
This commit is contained in:
parent
0077b4c5a4
commit
fa3cd4f53c
3 changed files with 8 additions and 2 deletions
2
.npmrc
2
.npmrc
|
@ -3,8 +3,6 @@ prefer-workspace-packages=true
|
|||
link-workspace-packages=true
|
||||
save-workspace-protocol=false # This prevents the examples to have the `workspace:` prefix
|
||||
|
||||
use-node-version=14.19.0
|
||||
|
||||
# Rather than shamefully hoisting everything, just make problematic packages public
|
||||
public-hoist-pattern[]=autoprefixer
|
||||
public-hoist-pattern[]=astro
|
||||
|
|
|
@ -23,6 +23,8 @@ export interface PreviewServer {
|
|||
stop(): Promise<void>;
|
||||
}
|
||||
|
||||
const HAS_FILE_EXTENSION_REGEXP = /^.*\.[^\\]+$/;
|
||||
|
||||
/** The primary dev action */
|
||||
export default async function preview(config: AstroConfig, { logging }: PreviewOptions): Promise<PreviewServer> {
|
||||
const startServerTime = performance.now();
|
||||
|
@ -60,6 +62,9 @@ export default async function preview(config: AstroConfig, { logging }: PreviewO
|
|||
case hasTrailingSlash && trailingSlash == 'never' && !isRoot:
|
||||
sendError('Not Found (devOptions.trailingSlash is set to "never")');
|
||||
return;
|
||||
case !hasTrailingSlash && trailingSlash == 'always' && !isRoot && !HAS_FILE_EXTENSION_REGEXP.test(pathname):
|
||||
sendError('Not Found (devOptions.trailingSlash is set to "always")');
|
||||
return;
|
||||
default: {
|
||||
// HACK: rewrite req.url so that sirv finds the file
|
||||
req.url = '/' + req.url?.replace(baseURL.pathname, '')
|
||||
|
|
|
@ -12,6 +12,9 @@ describe('Preview Routing', () => {
|
|||
before(async () => {
|
||||
fixture = await loadFixture({
|
||||
projectRoot: './fixtures/with-subpath-no-trailing-slash/',
|
||||
buildOptions: {
|
||||
pageUrlFormat: 'directory',
|
||||
},
|
||||
devOptions: {
|
||||
trailingSlash: 'never',
|
||||
port: 4000,
|
||||
|
|
Loading…
Reference in a new issue