-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix:
astro:server:setup
middleware (#6781)
* Revert "Fix: stop executing `astro:server:setup` twice (#6693)" This reverts commit c0b7864. * fix: delay `astro:server:setup` to `configureServer` * test: middleware from astro:server:setup * chore: lock * chore: changeset * chore: remove minimal example change * chore: revert minimal env change
- Loading branch information
1 parent
8a0336c
commit 7f74326
Showing
9 changed files
with
87 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'astro': patch | ||
--- | ||
|
||
Fix `astro:server:setup` middlewares not applying. This resolves an issue with the Partytown integration in dev. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
packages/astro/src/vite-plugin-integrations-container/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import type { Plugin as VitePlugin } from 'vite'; | ||
import type { AstroSettings } from '../@types/astro.js'; | ||
import type { LogOptions } from '../core/logger/core.js'; | ||
import { runHookServerSetup } from '../integrations/index.js'; | ||
|
||
/** Connect Astro integrations into Vite, as needed. */ | ||
export default function astroIntegrationsContainerPlugin({ | ||
settings, | ||
logging, | ||
}: { | ||
settings: AstroSettings; | ||
logging: LogOptions; | ||
}): VitePlugin { | ||
return { | ||
name: 'astro:integration-container', | ||
configureServer(server) { | ||
runHookServerSetup({ config: settings.config, server, logging }); | ||
}, | ||
}; | ||
} |
6 changes: 6 additions & 0 deletions
6
packages/astro/test/fixtures/integration-server-setup/astro.config.mjs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { defineConfig } from 'rollup' | ||
import test from './integration.js' | ||
|
||
export default defineConfig({ | ||
integrations: [test()] | ||
}) |
15 changes: 15 additions & 0 deletions
15
packages/astro/test/fixtures/integration-server-setup/integration.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
export default function() { | ||
return { | ||
name: '@astrojs/test-integration', | ||
hooks: { | ||
'astro:server:setup': ({ server }) => { | ||
server.middlewares.use( | ||
function middleware(req, res, next) { | ||
res.setHeader('x-middleware', 'true'); | ||
next(); | ||
} | ||
); | ||
} | ||
} | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
packages/astro/test/fixtures/integration-server-setup/package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"name": "@test/integration-server-setup", | ||
"type": "module", | ||
"version": "0.0.0", | ||
"private": true, | ||
"dependencies": { | ||
"astro": "workspace:*" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { expect } from 'chai'; | ||
import { loadFixture } from './test-utils.js'; | ||
|
||
describe('Integration server setup', () => { | ||
/** @type {import('./test-utils').DevServer} */ | ||
let devServer; | ||
/** @type {import('./test-utils').Fixture} */ | ||
let fixture; | ||
|
||
before(async () => { | ||
fixture = await loadFixture({ root: './fixtures/integration-server-setup/' }); | ||
devServer = await fixture.startDevServer(); | ||
}); | ||
|
||
after(async () => { | ||
await devServer.stop(); | ||
}); | ||
|
||
it('Adds middlewares in dev', async () => { | ||
const res = await fixture.fetch('/'); | ||
|
||
expect(res.headers.get('x-middleware')).to.equal('true'); | ||
}); | ||
}); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.