Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

fix: Add allowed origins + redirect

Richie McIlroyf59fd20b42cc
diff --git a/app-icon.png b/app-icon.png
index f5e262a46..b1ac1ef7d 100644
Binary files a/app-icon.png and b/app-icon.png differ
diff --git a/apps/web/app/api/desktop/session/request/route.ts b/apps/web/app/api/desktop/session/request/route.ts
index 4bbb422e4..3cc7c3599 100644
--- a/apps/web/app/api/desktop/session/request/route.ts
+++ b/apps/web/app/api/desktop/session/request/route.ts
@@ -14,7 +14,9 @@ export async function GET(req: NextRequest) {
});
if (!token) {
- return Response.redirect(`${process.env.NEXT_PUBLIC_URL}/login`);
+ return Response.redirect(
+ `${process.env.NEXT_PUBLIC_URL}/login?next=api/desktop/session/request?port=${port}`
+ );
}
const encodedToken = await encode({
diff --git a/apps/web/app/api/desktop/video/create/route.ts b/apps/web/app/api/desktop/video/create/route.ts
index 7b32ca050..e5e74d793 100644
--- a/apps/web/app/api/desktop/video/create/route.ts
+++ b/apps/web/app/api/desktop/video/create/route.ts
@@ -9,11 +9,23 @@ export async function GET(req: NextRequest) {
const awsRegion = process.env.CAP_AWS_REGION;
const awsBucket = process.env.CAP_AWS_BUCKET;
+ const allowedOrigins = [
+ process.env.NEXT_PUBLIC_URL,
+ "tauri://localhost",
+ "http://localhost:3001",
+ ];
+ const requestOrigin = req.headers.get("origin") || "";
+ const allowedOrigin = allowedOrigins.includes(requestOrigin)
+ ? requestOrigin
+ : false;
+
if (!user) {
return new Response(JSON.stringify({ error: true }), {
status: 401,
headers: {
"Content-Type": "application/json",
+ ...(allowedOrigin && { "Access-Control-Allow-Origin": allowedOrigin }),
+ "Access-Control-Allow-Credentials": "true",
},
});
}
@@ -38,6 +50,8 @@ export async function GET(req: NextRequest) {
status: 200,
headers: {
"Content-Type": "application/json",
+ ...(allowedOrigin && { "Access-Control-Allow-Origin": allowedOrigin }),
+ "Access-Control-Allow-Credentials": "true",
},
}
);
diff --git a/apps/web/next.config.mjs b/apps/web/next.config.mjs
index 8af1118e9..a4bb34d20 100644
--- a/apps/web/next.config.mjs
+++ b/apps/web/next.config.mjs
@@ -81,7 +81,7 @@ const nextConfig = {
headers: [
{
key: "Access-Control-Allow-Origin",
- value: "*",
+ value: "tauri://localhost",
},
{
key: "Access-Control-Allow-Methods",
@@ -91,6 +91,31 @@ const nextConfig = {
key: "Access-Control-Allow-Headers",
value: "Content-Type, Authorization",
},
+ {
+ key: "Access-Control-Allow-Credentials",
+ value: "true",
+ },
+ ],
+ },
+ {
+ source: "/api/desktop/(.*)",
+ headers: [
+ {
+ key: "Access-Control-Allow-Origin",
+ value: "http://localhost:3001",
+ },
+ {
+ key: "Access-Control-Allow-Methods",
+ value: "GET, POST, PUT, DELETE, OPTIONS",
+ },
+ {
+ key: "Access-Control-Allow-Headers",
+ value: "Content-Type, Authorization",
+ },
+ {
+ key: "Access-Control-Allow-Credentials",
+ value: "true",
+ },
],
},
];