Skip to content

Commit

Permalink
Project: add cors headers for export
Browse files Browse the repository at this point in the history
  • Loading branch information
JohannaPeanut committed Feb 5, 2025
1 parent b13c188 commit 7980f94
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions src/app/api/projects/[slug]/route.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
import db from "@/db"
import { featureCollection, lineString } from "@turf/helpers"

const corsHeaders = {
"Content-Type": "application/json",
"Access-Control-Allow-Origin": "*",
"Access-Control-Allow-Methods": "GET, POST, PUT, DELETE, OPTIONS",
"Access-Control-Allow-Headers": "Content-Type, Authorization",
}

export async function GET(request: Request, { params }: { params: Promise<{ slug: string }> }) {
try {
const slug = (await params).slug
Expand All @@ -15,13 +22,14 @@ export async function GET(request: Request, { params }: { params: Promise<{ slug
console.log("No project found for slug: ", slug)
return new Response(JSON.stringify({ error: "No project found for that slug" }), {
status: 404,
headers: corsHeaders,
})
}
if (!project.exportEnabled) {
console.log("Export is disabled for project with slug: ", slug)
return new Response(
JSON.stringify({ error: "The export for this project is disabled by the admin" }),
{ status: 404 },
{ status: 404, headers: corsHeaders },
)
}

Expand Down Expand Up @@ -50,10 +58,13 @@ export async function GET(request: Request, { params }: { params: Promise<{ slug
)

return new Response(JSON.stringify(projectFeatures), {
headers: { "Content-Type": "application/json" },
headers: corsHeaders,
})
} catch (error) {
console.error("Error fetching subsections:", error)
return new Response(JSON.stringify({ error: "Internal Server Error" }), { status: 500 })
return new Response(JSON.stringify({ error: "Internal Server Error" }), {
status: 500,
headers: corsHeaders,
})
}
}

0 comments on commit 7980f94

Please sign in to comment.