Created
February 25, 2023 15:04
-
-
Save nwellis/1ec03199e587bc73dea979cc118d137e to your computer and use it in GitHub Desktop.
Proxy server for Astro dev server
This file contains hidden or 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
| import { createProxyMiddleware } from "http-proxy-middleware" | |
| /** | |
| * Usage: | |
| * ```js | |
| * proxyMiddleware("proxy/path", { | |
| * target: "https://target.proxy.io", | |
| * changeOrigin: true, | |
| * }), | |
| * ``` | |
| * | |
| * @param {Parameters<createProxyMiddleware>[0]} context | |
| * @param {Parameters<createProxyMiddleware>[1]} options | |
| * | |
| * @returns @type {import('astro').AstroIntegration} | |
| * @see https://www.npmjs.com/package/http-proxy-middleware | |
| */ | |
| export default (context, options) => { | |
| const apiProxy = createProxyMiddleware(context, options) | |
| /** @type {import('astro').AstroIntegration} */ | |
| const integration = { | |
| name: 'proxy-middleware', | |
| hooks: { | |
| 'astro:server:setup': ({ server }) => { | |
| server.middlewares.use(apiProxy) | |
| } | |
| } | |
| } | |
| return integration | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment