Skip to content

Commit b4aceaf

Browse files
authored
Self hosted fixes (#1332)
* don't rely on NEXT_PUBLIC_WEB_URL in embed code * add /embed to allowed self hosting routes * remove videos
1 parent 415d93d commit b4aceaf

File tree

4 files changed

+33
-26
lines changed

4 files changed

+33
-26
lines changed

apps/web/app/(org)/dashboard/caps/components/SharingDialog.tsx

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,14 @@ import { useMutation } from "@tanstack/react-query";
1616
import clsx from "clsx";
1717
import { motion } from "framer-motion";
1818
import { Check, Globe2, Search } from "lucide-react";
19-
import { useCallback, useEffect, useState } from "react";
19+
import { useCallback, useEffect, useMemo, useState } from "react";
2020
import { toast } from "sonner";
2121
import { shareCap } from "@/actions/caps/share";
2222
import { useDashboardContext } from "@/app/(org)/dashboard/Contexts";
2323
import type { Spaces } from "@/app/(org)/dashboard/dashboard-data";
2424
import { SignedImageUrl } from "@/components/SignedImageUrl";
2525
import { Tooltip } from "@/components/Tooltip";
26+
import { usePublicEnv } from "@/utils/public-env";
2627

2728
interface SharingDialogProps {
2829
isOpen: boolean;
@@ -182,13 +183,9 @@ export const SharingDialog: React.FC<SharingDialogProps> = ({
182183
});
183184
};
184185

185-
const handleCopyEmbedCode = async () => {
186-
const embedCode = `<div style="position: relative; padding-bottom: 56.25%; height: 0;"><iframe src="${
187-
process.env.NODE_ENV === "development"
188-
? process.env.NEXT_PUBLIC_WEB_URL
189-
: "https://cap.so"
190-
}/embed/${capId}" frameborder="0" webkitallowfullscreen mozallowfullscreen allowfullscreen style="position: absolute; top: 0; left: 0; width: 100%; height: 100%;"></iframe></div>`;
186+
const embedCode = useEmbedCode(capId);
191187

188+
const handleCopyEmbedCode = async () => {
192189
try {
193190
await navigator.clipboard.writeText(embedCode);
194191
toast.success("Embed code copied to clipboard");
@@ -325,11 +322,7 @@ export const SharingDialog: React.FC<SharingDialogProps> = ({
325322
<div className="space-y-4">
326323
<div className="p-3 rounded-lg border bg-gray-3 border-gray-4">
327324
<code className="font-mono text-xs break-all text-gray-11">
328-
{`<div style="position: relative; padding-bottom: 56.25%; height: 0;"><iframe src="${
329-
process.env.NODE_ENV === "development"
330-
? process.env.NEXT_PUBLIC_WEB_URL
331-
: "https://cap.so"
332-
}/embed/${capId}" frameborder="0" webkitallowfullscreen mozallowfullscreen allowfullscreen style="position: absolute; top: 0; left: 0; width: 100%; height: 100%;"></iframe></div>`}
325+
{embedCode}
333326
</code>
334327
</div>
335328
<Button
@@ -447,3 +440,28 @@ const SpaceCard = ({
447440
</Tooltip>
448441
);
449442
};
443+
444+
function useEmbedCode(capId: Video.VideoId) {
445+
const publicEnv = usePublicEnv();
446+
447+
return useMemo(
448+
() =>
449+
`
450+
<div style="position: relative; padding-bottom: 56.25%; height: 0;">
451+
<iframe
452+
src="${publicEnv.webUrl}/embed/${capId}"
453+
frameborder="0"
454+
webkitallowfullscreen
455+
mozallowfullscreen
456+
allowfullscreen
457+
style="position: absolute; top: 0; left: 0; width: 100%; height: 100%;"
458+
></iframe>
459+
</div>
460+
`
461+
.trim()
462+
.replace(/[\n\t]+/g, " ")
463+
.replace(/>\s+</g, "><")
464+
.replace(/"\s+>/g, '">'),
465+
[publicEnv.webUrl, capId],
466+
);
467+
}

apps/web/app/embed/[videoId]/page.tsx

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -162,13 +162,7 @@ export default async function EmbedVideoPage(
162162
return Option.fromNullable(video);
163163
}).pipe(
164164
Effect.flatten,
165-
Effect.map(
166-
(video) =>
167-
({
168-
needsPassword: false,
169-
video,
170-
}) as const,
171-
),
165+
Effect.map((video) => ({ needsPassword: false, video }) as const),
172166
Effect.catchTag("VerifyVideoPasswordError", () =>
173167
Effect.succeed({ needsPassword: true } as const),
174168
),
@@ -191,7 +185,7 @@ export default async function EmbedVideoPage(
191185
</p>
192186
</div>,
193187
),
194-
NoSuchElementException: () => Effect.sync(notFound()),
188+
NoSuchElementException: () => Effect.sync(() => notFound()),
195189
}),
196190
provideOptionalAuth,
197191
EffectRuntime.runPromise,

apps/web/content/docs/self-hosting.mdx

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,6 @@ and [MinIO](https://min.io) for storing videos.
4040

4141
Once deployed, login email links will be available in Railway’s Deploy Logs.
4242

43-
<video src="https://cap.so/api/playlist/?videoId=6s8mpx2t4epkwrm" controls />
44-
4543
### Custom Deployment with Docker
4644

4745
The [Cap Web Docker image](https://github.com/CapSoftware/Cap/pkgs/container/cap-web)
@@ -56,8 +54,6 @@ Copy the URL of your Cap Web deployment, and set the 'Cap Server URL'
5654
in Cap Desktop's settings page to this URL.
5755
Uploads from Cap Desktop will now be sent to your Cap Web deployment.
5856

59-
<video src="https://cap.so/api/playlist/?videoId=sh5ch60pbs02eec" controls />
60-
6157
## Email Login Links
6258

6359
If the `RESEND_API_KEY` and `RESEND_FROM_DOMAIN` environment variables are not set,
@@ -68,8 +64,6 @@ To send login links via email, you'll need to configure [Resend](https://resend.
6864
2. Connect a domain and set it as `RESEND_FROM_DOMAIN`
6965
3. Generate an API key and set it as `RESEND_API_KEY`
7066

71-
<video src="https://cap.so/api/playlist/?videoId=xyz74j90rr4br3a" controls />
72-
7367
## Support
7468

7569
If you encounter a problem with the Docker image or think this documentation is lacking,

apps/web/middleware.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ export async function middleware(request: NextRequest) {
4141
if (
4242
!(
4343
path.startsWith("/s/") ||
44+
path.startsWith("/middleware") ||
4445
path.startsWith("/dashboard") ||
4546
path.startsWith("/onboarding") ||
4647
path.startsWith("/api") ||

0 commit comments

Comments
 (0)