diff options
author | 2023-11-09 09:49:35 -0800 | |
---|---|---|
committer | 2023-11-09 12:49:35 -0500 | |
commit | 83c88706848521922ccd9cbdd914b653e47309db (patch) | |
tree | 925696d9995f323b1251a32fae0bce200f228005 /.changeset/khaki-glasses-raise.md | |
parent | 4ce20b6fc9f6a216e91ca6fa2946ebbff8bba71d (diff) | |
download | astro-83c88706848521922ccd9cbdd914b653e47309db.tar.gz astro-83c88706848521922ccd9cbdd914b653e47309db.tar.zst astro-83c88706848521922ccd9cbdd914b653e47309db.zip |
[ci] release (#9021)astro@3.5.0@astrojs/mdx@1.1.4@astrojs/markdown-remark@3.4.0@astrojs/lit@3.0.3
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Diffstat (limited to '.changeset/khaki-glasses-raise.md')
-rw-r--r-- | .changeset/khaki-glasses-raise.md | 48 |
1 files changed, 0 insertions, 48 deletions
diff --git a/.changeset/khaki-glasses-raise.md b/.changeset/khaki-glasses-raise.md deleted file mode 100644 index 4a0622a42..000000000 --- a/.changeset/khaki-glasses-raise.md +++ /dev/null @@ -1,48 +0,0 @@ ---- -'astro': minor ---- - -## Integration Hooks to add Middleware - -It's now possible in Astro for an integration to add middleware on behalf of the user. Previously when a third party wanted to provide middleware, the user would need to create a `src/middleware.ts` file themselves. Now, adding third-party middleware is as easy as adding a new integration. - -For integration authors, there is a new `addMiddleware` function in the `astro:config:setup` hook. This function allows you to specify a middleware module and the order in which it should be applied: - -```js -// my-package/middleware.js -import { defineMiddleware } from 'astro:middleware'; - -export const onRequest = defineMiddleware(async (context, next) => { - const response = await next(); - - if(response.headers.get('content-type') === 'text/html') { - let html = await response.text(); - html = minify(html); - return new Response(html, { - status: response.status, - headers: response.headers - }); - } - - return response; -}); -``` - -You can now add your integration's middleware and specify that it runs either before or after the application's own defined middleware (defined in `src/middleware.{js,ts}`) - -```js -// my-package/integration.js -export function myIntegration() { - return { - name: 'my-integration', - hooks: { - 'astro:config:setup': ({ addMiddleware }) => { - addMiddleware({ - entrypoint: 'my-package/middleware', - order: 'pre' - }); - } - } - }; -} -``` |