diff --git a/legacy/netlify.toml b/legacy/netlify.toml index 5be194cb..7f0ca742 100644 --- a/legacy/netlify.toml +++ b/legacy/netlify.toml @@ -22,20 +22,6 @@ from = "/bigtest/*" status = 200 to = "https://bigtest.netlify.app/bigtest/:splat" -[[redirects]] -force = true -from = "/effection/*" -status = 200 -to = "https://effection.deno.dev/:splat" -headers = { X-Base-Url = "https://frontside.com/effection" } - -[[redirects]] -force = true -from = "/graphgen/*" -status = 200 -to = "https://graphgen.deno.dev/:splat" -headers = {X-Base = "https://frontside.com/graphgen/" } - [[redirects]] force = true from = "/platformscript/*" diff --git a/sitemap/proxy.ts b/sitemap/proxy.ts new file mode 100644 index 00000000..c0ba1f89 --- /dev/null +++ b/sitemap/proxy.ts @@ -0,0 +1,31 @@ +import { ServeHandler } from "../lib/types.ts"; +import { expect } from "effection"; + +export interface ProxyOptions { + website: string; + prefix: string; +} + +export function proxy(options: ProxyOptions): ServeHandler { + return function* handler({ request }) { + let website = new URL(options.website); + let target = new URL(request.url); + let prefix = new RegExp(`^\/${options.prefix}\/?`) + target.pathname = target.pathname.replace(prefix, "/"); + target.hostname = website.hostname; + target.port = website.port; + target.protocol = website.protocol; + + let base = new URL(`/${options.prefix}`, request.url); + + let response = yield* expect(fetch(target, { + redirect: "manual", + headers: { + ...request.headers, + "X-Base-Url": base.toString(), + } + })); + + return response; + } +} diff --git a/sitemap/sitemap.ts b/sitemap/sitemap.ts index 02bbeecc..33ab4b9c 100644 --- a/sitemap/sitemap.ts +++ b/sitemap/sitemap.ts @@ -6,6 +6,8 @@ import { GatsbyWebsite } from "../legacy/gatsby-website.ts"; import { AdvancedBackstagePluginDevelopmentHtml, AppHtml } from "../html.ts"; +import { proxy } from "./proxy.ts"; + export default () => serve({ "/workshops/advanced-backstage-plugin-development": html.get(() => @@ -21,5 +23,13 @@ export default () => AdvancedBackstagePluginDevelopmentHtml(), ) ), + "/effection(.*)": proxy({ + prefix: "effection", + website: "https://effection.deno.dev", + }), + "/graphgen(.*)": proxy({ + prefix: "graphgen", + website: "https://graphgen.deno.dev", + }), "(.*)": GatsbyWebsite, });