Skip to content

Commit

Permalink
fix: middleware entry point to not be set (#8036)
Browse files Browse the repository at this point in the history
* fix: middleware entry point to not be set

* chore: update tests
  • Loading branch information
ematipico committed Aug 11, 2023
1 parent fa3e839 commit 87d4b18
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 8 deletions.
5 changes: 5 additions & 0 deletions .changeset/rotten-flowers-know.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'astro': patch
---

Fix a bug where the middleware entry point was passed to integrations even though the configuration `build.excludeMiddleware` was set to `false`.
2 changes: 1 addition & 1 deletion packages/astro/src/core/build/plugins/plugin-middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export function vitePluginMiddleware(
if (chunk.type === 'asset') {
continue;
}
if (chunk.fileName === 'middleware.mjs') {
if (chunk.fileName === 'middleware.mjs' && opts.settings.config.build.excludeMiddleware) {
internals.middlewareEntryPoint = new URL(chunkName, opts.settings.config.build.server);
}
}
Expand Down
23 changes: 16 additions & 7 deletions packages/astro/test/middleware.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,13 +118,7 @@ describe('Middleware API in PROD mode, SSR', () => {
fixture = await loadFixture({
root: './fixtures/middleware-dev/',
output: 'server',
adapter: testAdapter({
setEntryPoints(entryPointsOrMiddleware) {
if (entryPointsOrMiddleware instanceof URL) {
middlewarePath = entryPointsOrMiddleware;
}
},
}),
adapter: testAdapter({}),
});
await fixture.build();
});
Expand Down Expand Up @@ -218,6 +212,21 @@ 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/',
output: 'server',
build: {
excludeMiddleware: true,
},
adapter: testAdapter({
setEntryPoints(entryPointsOrMiddleware) {
if (entryPointsOrMiddleware instanceof URL) {
middlewarePath = entryPointsOrMiddleware;
}
},
}),
});
await fixture.build();
expect(middlewarePath).to.not.be.undefined;
try {
const path = fileURLToPath(middlewarePath);
Expand Down

0 comments on commit 87d4b18

Please sign in to comment.