Skip to content

Commit

Permalink
Merge pull request #323 from thefrontside/directly-redirect-to-effect…
Browse files Browse the repository at this point in the history
…ion-and-graphgen

Proxy the Effection and Graphgen sites directly
  • Loading branch information
cowboyd authored Nov 7, 2023
2 parents b82e324 + 634bcab commit 40882b7
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 14 deletions.
14 changes: 0 additions & 14 deletions legacy/netlify.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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/*"
Expand Down
31 changes: 31 additions & 0 deletions sitemap/proxy.ts
Original file line number Diff line number Diff line change
@@ -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;
}
}
10 changes: 10 additions & 0 deletions sitemap/sitemap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(() =>
Expand All @@ -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,
});

0 comments on commit 40882b7

Please sign in to comment.