UNPKG

@softr/sdk

Version:

The SDK for building Softr apps on TanStack Start. It lets an app interact with Softr: auth, datasources, workflows and integrations.

33 lines (31 loc) • 1.02 kB
import { softrConfig } from "./softr-config.js"; import { createMiddleware } from "@tanstack/react-start"; //#region src/embedding.ts /** * Stops other sites from showing the published app in an iframe. The origins * softr.json lists in `allowEmbedding` still can. * * Production only. The dev server runs in the preview pod, and Studio shows * that preview in an iframe on another site. */ function embeddingMiddleware() { return createMiddleware({ type: "request" }).server(async ({ next }) => { const result = await next(); if (process.env.NODE_ENV !== "production") return result; const policy = [ "frame-ancestors", "'self'", ...softrConfig().allowEmbedding ?? [] ].join(" "); try { result.response.headers.append("content-security-policy", policy); return result; } catch { const response = new Response(result.response.body, result.response); response.headers.append("content-security-policy", policy); return response; } }); } //#endregion export { embeddingMiddleware };