summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Emanuele Stoppa <my.burning@gmail.com> 2023-08-11 12:24:12 +0100
committerGravatar GitHub <noreply@github.com> 2023-08-11 12:24:12 +0100
commit87d4b18437c7565c48cad4bea81831c2a244ebb8 (patch)
tree563cca5e4101a013e1103a39ac24c5ed52871960
parentfa3e83984343d3b9c37af7af876ad03ac95bf1c6 (diff)
downloadastro-87d4b18437c7565c48cad4bea81831c2a244ebb8.tar.gz
astro-87d4b18437c7565c48cad4bea81831c2a244ebb8.tar.zst
astro-87d4b18437c7565c48cad4bea81831c2a244ebb8.zip
fix: middleware entry point to not be set (#8036)
* fix: middleware entry point to not be set * chore: update tests
-rw-r--r--.changeset/rotten-flowers-know.md5
-rw-r--r--packages/astro/src/core/build/plugins/plugin-middleware.ts2
-rw-r--r--packages/astro/test/middleware.test.js23
3 files changed, 22 insertions, 8 deletions
diff --git a/.changeset/rotten-flowers-know.md b/.changeset/rotten-flowers-know.md
new file mode 100644
index 000000000..03ab03feb
--- /dev/null
+++ b/.changeset/rotten-flowers-know.md
@@ -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`.
diff --git a/packages/astro/src/core/build/plugins/plugin-middleware.ts b/packages/astro/src/core/build/plugins/plugin-middleware.ts
index 8afca2fbc..5ed532d5e 100644
--- a/packages/astro/src/core/build/plugins/plugin-middleware.ts
+++ b/packages/astro/src/core/build/plugins/plugin-middleware.ts
@@ -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);
}
}
diff --git a/packages/astro/test/middleware.test.js b/packages/astro/test/middleware.test.js
index 1ed857d5b..3796a341f 100644
--- a/packages/astro/test/middleware.test.js
+++ b/packages/astro/test/middleware.test.js
@@ -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();
});
@@ -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);