feat: Allow embedding /share/ routes in iframes
This commit is contained in:
@ -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
|
// serve static assets
|
||||||
koa.use(
|
koa.use(
|
||||||
serve(path.resolve(__dirname, "../../public"), {
|
serve(path.resolve(__dirname, "../../public"), {
|
||||||
@ -65,23 +81,14 @@ router.get("/opensearch.xml", (ctx) => {
|
|||||||
ctx.body = opensearchResponse();
|
ctx.body = opensearchResponse();
|
||||||
});
|
});
|
||||||
|
|
||||||
// catch all for application
|
router.get("/share/*", (ctx, next) => {
|
||||||
router.get("*", async (ctx, next) => {
|
ctx.remove("X-Frame-Options");
|
||||||
if (ctx.request.path === "/realtime/") {
|
return renderApp(ctx, next);
|
||||||
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 || "");
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// catch all for application
|
||||||
|
router.get("*", renderApp);
|
||||||
|
|
||||||
// middleware
|
// middleware
|
||||||
koa.use(apexRedirect());
|
koa.use(apexRedirect());
|
||||||
koa.use(router.routes());
|
koa.use(router.routes());
|
||||||
|
Reference in New Issue
Block a user