import type { DocumentContext, DocumentProps } from "next/document"; import Document, { Head, Html, Main, NextScript } from "next/document"; import Script from "next/script"; import { z } from "zod"; import { getDirFromLang } from "@calcom/lib/i18n"; import { csp } from "@lib/csp"; type Props = Record & DocumentProps; class MyDocument extends Document { static async getInitialProps(ctx: DocumentContext) { const { nonce } = csp(ctx.req || null, ctx.res || null); if (!process.env.CSP_POLICY) { ctx.res?.setHeader("x-csp", "not-opted-in"); } else if (!ctx.res?.getHeader("x-csp")) { // If x-csp not set by gSSP, then it's initialPropsOnly ctx.res?.setHeader("x-csp", "initialPropsOnly"); } const isEmbed = ctx.asPath?.includes("/embed") || ctx.asPath?.includes("embedType="); const initialProps = await Document.getInitialProps(ctx); return { isEmbed, nonce, ...initialProps }; } render() { const { locale } = this.props.__NEXT_DATA__; const { isEmbed } = this.props; const nonceParsed = z.string().safeParse(this.props.nonce); const nonce = nonceParsed.success ? nonceParsed.data : ""; const dir = getDirFromLang(locale); return (