diff --git a/.changeset/tidy-kiwis-lick.md b/.changeset/tidy-kiwis-lick.md new file mode 100644 index 000000000000..14a5284dddfa --- /dev/null +++ b/.changeset/tidy-kiwis-lick.md @@ -0,0 +1,5 @@ +--- +'astro': patch +--- + +Fixed an issue where spaces and unicode characters in project path prevented middleware from running. diff --git a/packages/astro/src/core/build/plugins/plugin-middleware.ts b/packages/astro/src/core/build/plugins/plugin-middleware.ts index 47ff4b863cf3..22d3f795ba89 100644 --- a/packages/astro/src/core/build/plugins/plugin-middleware.ts +++ b/packages/astro/src/core/build/plugins/plugin-middleware.ts @@ -25,7 +25,7 @@ export function vitePluginMiddleware( async resolveId(id) { if (id === MIDDLEWARE_MODULE_ID) { const middlewareId = await this.resolve( - `${opts.settings.config.srcDir.pathname}/${MIDDLEWARE_PATH_SEGMENT_NAME}` + `${decodeURI(opts.settings.config.srcDir.pathname)}${MIDDLEWARE_PATH_SEGMENT_NAME}` ); if (middlewareId) { resolvedMiddlewareId = middlewareId.id; diff --git a/packages/astro/src/core/middleware/loadMiddleware.ts b/packages/astro/src/core/middleware/loadMiddleware.ts index 9a7f3e4bc4cc..b8528eb4b336 100644 --- a/packages/astro/src/core/middleware/loadMiddleware.ts +++ b/packages/astro/src/core/middleware/loadMiddleware.ts @@ -12,7 +12,7 @@ export async function loadMiddleware( srcDir: AstroSettings['config']['srcDir'] ) { // can't use node Node.js builtins - let middlewarePath = srcDir.pathname + '/' + MIDDLEWARE_PATH_SEGMENT_NAME; + let middlewarePath = `${decodeURI(srcDir.pathname)}${MIDDLEWARE_PATH_SEGMENT_NAME}`; try { const module = await moduleLoader.import(middlewarePath); return module; diff --git a/packages/astro/test/featuresSupport.test.js b/packages/astro/test/featuresSupport.test.js index fba8da47557d..c25d9d5f8f08 100644 --- a/packages/astro/test/featuresSupport.test.js +++ b/packages/astro/test/featuresSupport.test.js @@ -8,7 +8,7 @@ describe('Adapter', () => { it("should error if the adapter doesn't support edge middleware", async () => { try { fixture = await loadFixture({ - root: './fixtures/middleware-dev/', + root: './fixtures/middleware space/', output: 'server', build: { excludeMiddleware: true, @@ -32,7 +32,7 @@ describe('Adapter', () => { it("should error if the adapter doesn't support split build", async () => { try { fixture = await loadFixture({ - root: './fixtures/middleware-dev/', + root: './fixtures/middleware space/', output: 'server', build: { split: true, diff --git a/packages/astro/test/fixtures/middleware-dev/package.json b/packages/astro/test/fixtures/middleware space/package.json similarity index 100% rename from packages/astro/test/fixtures/middleware-dev/package.json rename to packages/astro/test/fixtures/middleware space/package.json diff --git a/packages/astro/test/fixtures/middleware-dev/src/middleware.js b/packages/astro/test/fixtures/middleware space/src/middleware.js similarity index 100% rename from packages/astro/test/fixtures/middleware-dev/src/middleware.js rename to packages/astro/test/fixtures/middleware space/src/middleware.js diff --git a/packages/astro/test/fixtures/middleware-dev/src/pages/404.astro b/packages/astro/test/fixtures/middleware space/src/pages/404.astro similarity index 100% rename from packages/astro/test/fixtures/middleware-dev/src/pages/404.astro rename to packages/astro/test/fixtures/middleware space/src/pages/404.astro diff --git a/packages/astro/test/fixtures/middleware-dev/src/pages/api/endpoint.js b/packages/astro/test/fixtures/middleware space/src/pages/api/endpoint.js similarity index 100% rename from packages/astro/test/fixtures/middleware-dev/src/pages/api/endpoint.js rename to packages/astro/test/fixtures/middleware space/src/pages/api/endpoint.js diff --git a/packages/astro/test/fixtures/middleware-dev/src/pages/broken-500.astro b/packages/astro/test/fixtures/middleware space/src/pages/broken-500.astro similarity index 100% rename from packages/astro/test/fixtures/middleware-dev/src/pages/broken-500.astro rename to packages/astro/test/fixtures/middleware space/src/pages/broken-500.astro diff --git a/packages/astro/test/fixtures/middleware-dev/src/pages/broken-locals.astro b/packages/astro/test/fixtures/middleware space/src/pages/broken-locals.astro similarity index 100% rename from packages/astro/test/fixtures/middleware-dev/src/pages/broken-locals.astro rename to packages/astro/test/fixtures/middleware space/src/pages/broken-locals.astro diff --git a/packages/astro/test/fixtures/middleware-dev/src/pages/clone.astro b/packages/astro/test/fixtures/middleware space/src/pages/clone.astro similarity index 100% rename from packages/astro/test/fixtures/middleware-dev/src/pages/clone.astro rename to packages/astro/test/fixtures/middleware space/src/pages/clone.astro diff --git a/packages/astro/test/fixtures/middleware-dev/src/pages/does-nothing.astro b/packages/astro/test/fixtures/middleware space/src/pages/does-nothing.astro similarity index 100% rename from packages/astro/test/fixtures/middleware-dev/src/pages/does-nothing.astro rename to packages/astro/test/fixtures/middleware space/src/pages/does-nothing.astro diff --git a/packages/astro/test/fixtures/middleware-dev/src/pages/index.astro b/packages/astro/test/fixtures/middleware space/src/pages/index.astro similarity index 100% rename from packages/astro/test/fixtures/middleware-dev/src/pages/index.astro rename to packages/astro/test/fixtures/middleware space/src/pages/index.astro diff --git a/packages/astro/test/fixtures/middleware-dev/src/pages/lorem.astro b/packages/astro/test/fixtures/middleware space/src/pages/lorem.astro similarity index 100% rename from packages/astro/test/fixtures/middleware-dev/src/pages/lorem.astro rename to packages/astro/test/fixtures/middleware space/src/pages/lorem.astro diff --git a/packages/astro/test/fixtures/middleware-dev/src/pages/not-interested.astro b/packages/astro/test/fixtures/middleware space/src/pages/not-interested.astro similarity index 100% rename from packages/astro/test/fixtures/middleware-dev/src/pages/not-interested.astro rename to packages/astro/test/fixtures/middleware space/src/pages/not-interested.astro diff --git a/packages/astro/test/fixtures/middleware-dev/src/pages/redirect.astro b/packages/astro/test/fixtures/middleware space/src/pages/redirect.astro similarity index 100% rename from packages/astro/test/fixtures/middleware-dev/src/pages/redirect.astro rename to packages/astro/test/fixtures/middleware space/src/pages/redirect.astro diff --git a/packages/astro/test/fixtures/middleware-dev/src/pages/rewrite.astro b/packages/astro/test/fixtures/middleware space/src/pages/rewrite.astro similarity index 100% rename from packages/astro/test/fixtures/middleware-dev/src/pages/rewrite.astro rename to packages/astro/test/fixtures/middleware space/src/pages/rewrite.astro diff --git a/packages/astro/test/fixtures/middleware-dev/src/pages/second.astro b/packages/astro/test/fixtures/middleware space/src/pages/second.astro similarity index 100% rename from packages/astro/test/fixtures/middleware-dev/src/pages/second.astro rename to packages/astro/test/fixtures/middleware space/src/pages/second.astro diff --git a/packages/astro/test/middleware.test.js b/packages/astro/test/middleware.test.js index 9ca4841d4e4e..81f167647b59 100644 --- a/packages/astro/test/middleware.test.js +++ b/packages/astro/test/middleware.test.js @@ -12,7 +12,7 @@ describe('Middleware in DEV mode', () => { before(async () => { fixture = await loadFixture({ - root: './fixtures/middleware-dev/', + root: './fixtures/middleware space/', }); devServer = await fixture.startDevServer(); }); @@ -116,7 +116,7 @@ describe('Middleware API in PROD mode, SSR', () => { before(async () => { fixture = await loadFixture({ - root: './fixtures/middleware-dev/', + root: './fixtures/middleware space/', output: 'server', adapter: testAdapter({}), }); @@ -223,7 +223,7 @@ describe('Middleware API in PROD mode, SSR', () => { it('the integration should receive the path to the middleware', async () => { fixture = await loadFixture({ - root: './fixtures/middleware-dev/', + root: './fixtures/middleware space/', output: 'server', build: { excludeMiddleware: true, @@ -275,7 +275,7 @@ describe('Middleware, split middleware option', () => { before(async () => { fixture = await loadFixture({ - root: './fixtures/middleware-dev/', + root: './fixtures/middleware space/', output: 'server', build: { excludeMiddleware: true, diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 1aebf6930f4c..eb5e684fa34b 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -2847,7 +2847,7 @@ importers: specifier: workspace:* version: link:../../.. - packages/astro/test/fixtures/middleware-dev: + packages/astro/test/fixtures/middleware space: dependencies: astro: specifier: workspace:*