Open source Loom alternative. Beautiful, shareable screen recordings.
Rust appcapcossloommacnextjsnextjs15open-sourceossreactrecordrustscreen-capturescreen-recorderscreenshotsolidjstauritauri-apptypescriptvite
fix: Remove CORS from next.config, apply directly in route
Richie McIlroy6ff23336f5b9
diff --git a/apps/web/app/api/playlist/route.ts b/apps/web/app/api/playlist/route.tsindex f66f90e0b..909354ba9 100644--- a/apps/web/app/api/playlist/route.ts+++ b/apps/web/app/api/playlist/route.ts@@ -12,8 +12,25 @@ import { getSignedUrl } from "@aws-sdk/s3-request-presigner";import { getCurrentUser } from "@cap/database/auth/session";import { generateM3U8Playlist } from "@/utils/video/ffmpeg/helpers";+const allowedOrigins = [process.env.NEXT_PUBLIC_URL, "https://cap.link"];+export const revalidate = 3500;+export async function OPTIONS(request: NextRequest) {+ return new Response(null, {+ status: 200,+ headers: {+ "Access-Control-Allow-Origin": allowedOrigins.includes(+ request.nextUrl.origin+ )+ ? origin+ : "null",+ "Access-Control-Allow-Credentials": "true",+ "Access-Control-Allow-Methods": "GET, OPTIONS",+ },+ });+}+export async function GET(request: NextRequest) {const searchParams = request.nextUrl.searchParams;const userId = searchParams.get("userId") || "";@@ -30,7 +47,13 @@ export async function GET(request: NextRequest) {{status: 401,headers: {- "Content-Type": "application/json",+ "Access-Control-Allow-Origin": allowedOrigins.includes(+ request.nextUrl.origin+ )+ ? origin+ : "null",+ "Access-Control-Allow-Credentials": "true",+ "Access-Control-Allow-Methods": "GET, OPTIONS",},});@@ -44,7 +67,13 @@ export async function GET(request: NextRequest) {{status: 401,headers: {- "Content-Type": "application/json",+ "Access-Control-Allow-Origin": allowedOrigins.includes(+ request.nextUrl.origin+ )+ ? origin+ : "null",+ "Access-Control-Allow-Credentials": "true",+ "Access-Control-Allow-Methods": "GET, OPTIONS",},});@@ -61,7 +90,13 @@ export async function GET(request: NextRequest) {{status: 401,headers: {- "Content-Type": "application/json",+ "Access-Control-Allow-Origin": allowedOrigins.includes(+ request.nextUrl.origin+ )+ ? origin+ : "null",+ "Access-Control-Allow-Credentials": "true",+ "Access-Control-Allow-Methods": "GET, OPTIONS",},});@@ -100,7 +135,13 @@ export async function GET(request: NextRequest) {{status: 401,headers: {- "Content-Type": "application/json",+ "Access-Control-Allow-Origin": allowedOrigins.includes(+ request.nextUrl.origin+ )+ ? origin+ : "null",+ "Access-Control-Allow-Credentials": "true",+ "Access-Control-Allow-Methods": "GET, OPTIONS",},});@@ -139,7 +180,16 @@ export async function GET(request: NextRequest) {return new Response(generatedPlaylist, {status: 200,- headers: { "content-type": "application/x-mpegURL" },+ headers: {+ "content-type": "application/x-mpegURL",+ "Access-Control-Allow-Origin": allowedOrigins.includes(+ request.nextUrl.origin+ )+ ? origin+ : "null",+ "Access-Control-Allow-Credentials": "true",+ "Access-Control-Allow-Methods": "GET, OPTIONS",+ },});} catch (error) {console.error("Error generating video segment URLs", error);diff --git a/apps/web/next.config.mjs b/apps/web/next.config.mjsindex 041ca9fdb..5d47e3b39 100644--- a/apps/web/next.config.mjs+++ b/apps/web/next.config.mjs@@ -40,119 +40,6 @@ const nextConfig = {},],},- async headers() {- return [- {- source: "/api/playlist/(.*)",- headers: async (req) => {- const allowedOrigins = ["https://cap.so", "https://cap.link"];- const origin = req.headers.origin;- if (allowedOrigins.includes(origin)) {- return [- {- key: "Access-Control-Allow-Origin",- value: origin,- },- {- key: "Access-Control-Allow-Methods",- value: "GET, POST, PUT, DELETE, OPTIONS",- },- {- key: "Access-Control-Allow-Credentials",- value: "true",- },- ];- } else {- return [];- }- },- },- {- source: "/api/desktop/(.*)",- headers: [- {- key: "Access-Control-Allow-Origin",- value: "http://tauri.localhost",- },- {- key: "Access-Control-Allow-Methods",- value: "GET, POST, PUT, DELETE, OPTIONS",- },- {- key: "Access-Control-Allow-Headers",- value: "Authorization",- },- {- key: "Access-Control-Allow-Credentials",- value: "true",- },- ],- },- {- source: "/api/desktop/(.*)",- headers: [- {- key: "Access-Control-Allow-Origin",- value: "tauri://localhost/",- },- {- key: "Access-Control-Allow-Methods",- value: "GET, POST, PUT, DELETE, OPTIONS",- },- {- key: "Access-Control-Allow-Headers",- value: "Authorization",- },- {- key: "Access-Control-Allow-Credentials",- value: "true",- },- ],- },- {- source: "/api/desktop/(.*)",- headers: [- {- key: "Access-Control-Allow-Origin",- value: "tauri://localhost",- },- {- key: "Access-Control-Allow-Methods",- value: "GET, POST, PUT, DELETE, OPTIONS",- },- {- key: "Access-Control-Allow-Headers",- value: "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: "Authorization",- },- {- key: "Access-Control-Allow-Credentials",- value: "true",- },- ],- },- ];- },async rewrites() {return [{