From bb7fcd1b6720f96b7057916538fb5b19bf04e539 Mon Sep 17 00:00:00 2001 From: Tom Moor Date: Wed, 23 Sep 2020 19:26:18 -0700 Subject: [PATCH] feat: Allow embedding /share/ routes in iframes --- server/routes.js | 37 ++++++++++++++++++++++--------------- 1 file changed, 22 insertions(+), 15 deletions(-) diff --git a/server/routes.js b/server/routes.js index ae634a94..537b5712 100644 --- a/server/routes.js +++ b/server/routes.js @@ -37,6 +37,22 @@ const readIndexFile = async (ctx) => { }); }; +const renderApp = async (ctx, next) => { + if (ctx.request.path === "/realtime/") { + return next(); + } + + const page = await readIndexFile(ctx); + const env = ` + window.env = ${JSON.stringify(environment)}; + `; + ctx.body = page + .toString() + .replace(/\/\/inject-env\/\//g, env) + .replace(/\/\/inject-sentry-dsn\/\//g, process.env.SENTRY_DSN || "") + .replace(/\/\/inject-slack-app-id\/\//g, process.env.SLACK_APP_ID || ""); +}; + // serve static assets koa.use( serve(path.resolve(__dirname, "../../public"), { @@ -65,23 +81,14 @@ router.get("/opensearch.xml", (ctx) => { ctx.body = opensearchResponse(); }); -// catch all for application -router.get("*", async (ctx, next) => { - if (ctx.request.path === "/realtime/") { - return next(); - } - - const page = await readIndexFile(ctx); - const env = ` - window.env = ${JSON.stringify(environment)}; - `; - ctx.body = page - .toString() - .replace(/\/\/inject-env\/\//g, env) - .replace(/\/\/inject-sentry-dsn\/\//g, process.env.SENTRY_DSN || "") - .replace(/\/\/inject-slack-app-id\/\//g, process.env.SLACK_APP_ID || ""); +router.get("/share/*", (ctx, next) => { + ctx.remove("X-Frame-Options"); + return renderApp(ctx, next); }); +// catch all for application +router.get("*", renderApp); + // middleware koa.use(apexRedirect()); koa.use(router.routes());