-
Notifications
You must be signed in to change notification settings - Fork 5
ENG-1395 Official deployment version cannot access database #751
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,6 @@ | ||
| #!/bin/bash | ||
| set -e | ||
| export ROAM_BUILD_SCRIPT=1 | ||
| npm install -g corepack@latest | ||
| corepack enable pnpm | ||
| pnpm install | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| import { NextResponse, NextRequest } from "next/server"; | ||
| import { | ||
| handleRouteError, | ||
| defaultOptionsHandler, | ||
| } from "~/utils/supabase/apiUtils"; | ||
|
|
||
| export const GET = (request: NextRequest): NextResponse => { | ||
| try { | ||
| const { SUPABASE_URL, SUPABASE_ANON_KEY } = process.env; | ||
| if (!SUPABASE_URL || !SUPABASE_ANON_KEY) | ||
| return new NextResponse("Missing variables", { status: 500 }); | ||
| return NextResponse.json( | ||
| // eslint-disable-next-line @typescript-eslint/naming-convention | ||
| { SUPABASE_URL, SUPABASE_ANON_KEY }, | ||
| { status: 200 }, | ||
| ); | ||
| } catch (e: unknown) { | ||
| return handleRouteError(request, e, "/api/supabase/env"); | ||
| } | ||
| }; | ||
|
|
||
| export const OPTIONS = defaultOptionsHandler; | ||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -5,6 +5,7 @@ import { fileURLToPath } from "node:url"; | |||||||||||||||||
| import dotenv from "dotenv"; | ||||||||||||||||||
| import { Vercel } from "@vercel/sdk"; | ||||||||||||||||||
|
|
||||||||||||||||||
| // eslint-disable-next-line @typescript-eslint/naming-convention | ||||||||||||||||||
| const __dirname = dirname(fileURLToPath(import.meta.url)); | ||||||||||||||||||
| const projectRoot = join(__dirname, ".."); | ||||||||||||||||||
| const baseParams: Record<string, string> = {}; | ||||||||||||||||||
|
|
@@ -106,11 +107,27 @@ const makeProductionEnv = async (vercel: Vercel, vercelToken: string) => { | |||||||||||||||||
| }; | ||||||||||||||||||
|
|
||||||||||||||||||
| const main = async (variant: Variant) => { | ||||||||||||||||||
| // Do not execute in deployment or github action. | ||||||||||||||||||
| if ( | ||||||||||||||||||
| if (process.env.ROAM_BUILD_SCRIPT) { | ||||||||||||||||||
maparent marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||
| // special case: production build | ||||||||||||||||||
| try { | ||||||||||||||||||
| const response = execSync('curl https://discoursegraphs.com/api/supabase/env'); | ||||||||||||||||||
| const asJson = JSON.parse(response.toString()) as Record<string, string>; | ||||||||||||||||||
| writeFileSync( | ||||||||||||||||||
| join(projectRoot, ".env"), | ||||||||||||||||||
| Object.entries(asJson).map(([k,v])=>`${k}=${v}`).join('\n') | ||||||||||||||||||
| ); | ||||||||||||||||||
|
Comment on lines
+115
to
+118
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🔴 Environment file written to wrong path - When Root CauseThe flow when
Impact: The Roam build will not receive the
Suggested change
Was this helpful? React with 👍 or 👎 to provide feedback.
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the base dotenv reads the content of .env in all cases. |
||||||||||||||||||
| return; | ||||||||||||||||||
| } catch (e) { | ||||||||||||||||||
| if (process.env.SUPABASE_URL && process.env.SUPABASE_ANON_KEY) | ||||||||||||||||||
| return; | ||||||||||||||||||
| throw new Error("Could not get environment from site"); | ||||||||||||||||||
| } | ||||||||||||||||||
| } | ||||||||||||||||||
| else if ( | ||||||||||||||||||
| process.env.HOME === "/vercel" || | ||||||||||||||||||
| process.env.GITHUB_ACTIONS !== undefined | ||||||||||||||||||
| ) | ||||||||||||||||||
| // Do not execute in deployment or github action. | ||||||||||||||||||
| return; | ||||||||||||||||||
|
|
||||||||||||||||||
| if (variant === Variant.none) return; | ||||||||||||||||||
|
|
||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🟡 Missing CORS headers on GET response while OPTIONS handler has them
The new
/api/supabase/envendpoint has inconsistent CORS handling. TheOPTIONShandler usesdefaultOptionsHandlerwhich applies CORS headers, but theGEThandler returnsNextResponse.json()directly without applying CORS via thecors()function.Root Cause
Other API endpoints in the codebase use
createApiResponse()which internally callscors(request, response)to add CORS headers (seeapps/website/app/utils/supabase/apiUtils.ts:48). However, this new endpoint bypasses that pattern.If this endpoint is ever called from a browser context (e.g., from the Roam extension at runtime), the browser would:
Access-Control-Allow-OriginCurrently this doesn't affect the build process since
curlis used (packages/database/scripts/createEnv.mts:113), but it makes the API inconsistent and would break any future browser-based usage.Was this helpful? React with 👍 or 👎 to provide feedback.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@maparent