diff options
author | 2022-12-13 17:05:21 +0630 | |
---|---|---|
committer | 2022-12-13 11:35:21 +0100 | |
commit | 9f0fea0ad7ef90325c9ff3d2bcc6cfe77c37515d (patch) | |
tree | ef0f0ccda8345881094131c190336b794a8330a2 | |
parent | dae6866ddcd957ffc282b29198150c2d5053a0ca (diff) | |
download | astro-9f0fea0ad7ef90325c9ff3d2bcc6cfe77c37515d.tar.gz astro-9f0fea0ad7ef90325c9ff3d2bcc6cfe77c37515d.tar.zst astro-9f0fea0ad7ef90325c9ff3d2bcc6cfe77c37515d.zip |
Add Vercel middleware docs to Vercel integration README (#5576)
Co-authored-by: Chris Swithinbank <swithinbank@gmail.com>
-rw-r--r-- | packages/integrations/vercel/README.md | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/packages/integrations/vercel/README.md b/packages/integrations/vercel/README.md index a5cbce5ca..2948e8b0f 100644 --- a/packages/integrations/vercel/README.md +++ b/packages/integrations/vercel/README.md @@ -129,6 +129,30 @@ export default defineConfig({ }); ``` +### Vercel Middleware + +You can use Vercel middleware to intercept a request and redirect before sending a response. Vercel middleware can run for Edge, SSR, and Static deployments. You don't need to install `@vercel/edge` to write middleware, but you do need to install it to use features such as geolocation. For more information see [Vercel’s middleware documentation](https://vercel.com/docs/concepts/functions/edge-middleware). + +1. Add a `middleware.js` file to the root of your project: + + ```js + // middleware.js + export const config = { + // Only run the middleware on the admin route + matcher: '/admin', + }; + + export default function middleware(request) { + const url = new URL(request.url); + // You can retrieve IP location or cookies here. + if (url.pathname === "/admin") { + url.pathname = "/" + } + return Response.redirect(url); + } + ``` +1. While developing locally, you can run `vercel dev` to run middleware. In production, Vercel will handle this for you. + ## Troubleshooting **A few known complex packages (example: [puppeteer](https://github.com/puppeteer/puppeteer)) do not support bundling and therefore will not work properly with this adapter.** By default, Vercel doesn't include npm installed files & packages from your project's `./node_modules` folder. To address this, the `@astrojs/vercel` adapter automatically bundles your final build output using `esbuild`. |