Skip to content

Commit 05b0956

Browse files
committed
Add debug endpoint and environment variable configuration for development testing
- Introduced a new debug endpoint to validate environment variables, accessible only in development or when explicitly enabled. - Updated the Next.js configuration to include the ENABLE_DEBUG_ENDPOINTS variable. - Added a temporary environment variable for enabling debug endpoints in the Fargate service configuration.
1 parent 08f1f4c commit 05b0956

File tree

3 files changed

+56
-0
lines changed

3 files changed

+56
-0
lines changed

apps/infra/index.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,10 @@ const service = new awsx.ecs.FargateService("pathfinder-service", {
355355
name: "DATABASE_URL",
356356
value: pulumi.interpolate`postgresql://${db.username}:${db.password}@${db.endpoint}/${db.dbName}`,
357357
},
358+
{
359+
name: "ENABLE_DEBUG_ENDPOINTS",
360+
value: "true", // Temporary: for debugging environment variables
361+
},
358362
],
359363
portMappings: [
360364
{

apps/web/next.config.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@ const nextConfig: NextConfig = {
88
output: "standalone",
99
// Add the packages in transpilePackages for standalone mode
1010
transpilePackages: ["@t3-oss/env-nextjs", "@t3-oss/env-core"],
11+
// Explicitly define environment variables for standalone mode
12+
env: {
13+
DATABASE_URL: process.env.DATABASE_URL,
14+
NODE_ENV: process.env.NODE_ENV,
15+
ENABLE_DEBUG_ENDPOINTS: process.env.ENABLE_DEBUG_ENDPOINTS,
16+
},
1117
};
1218

1319
export default nextConfig;
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import { env } from "@/env";
2+
import { NextResponse } from "next/server";
3+
4+
// Debug endpoint to test if the validated env works
5+
export async function GET() {
6+
// Only allow in development or if explicitly enabled
7+
if (
8+
process.env.NODE_ENV !== "development" &&
9+
!process.env.ENABLE_DEBUG_ENDPOINTS
10+
) {
11+
return NextResponse.json(
12+
{ error: "Debug endpoints disabled" },
13+
{ status: 403 }
14+
);
15+
}
16+
17+
try {
18+
// Try to access the validated environment variables
19+
const result = {
20+
status: "success",
21+
env: {
22+
DATABASE_URL: env.DATABASE_URL.replace(/:[^@]+@/, ":***@"), // Redacted
23+
NODE_ENV: env.NODE_ENV,
24+
},
25+
raw: {
26+
DATABASE_URL_exists: !!process.env.DATABASE_URL,
27+
DATABASE_URL_length: process.env.DATABASE_URL?.length || 0,
28+
},
29+
};
30+
31+
return NextResponse.json(result);
32+
} catch (error) {
33+
return NextResponse.json(
34+
{
35+
status: "error",
36+
error: error instanceof Error ? error.message : String(error),
37+
raw: {
38+
DATABASE_URL_exists: !!process.env.DATABASE_URL,
39+
DATABASE_URL_length: process.env.DATABASE_URL?.length || 0,
40+
SKIP_ENV_VALIDATION: process.env.SKIP_ENV_VALIDATION,
41+
},
42+
},
43+
{ status: 500 }
44+
);
45+
}
46+
}

0 commit comments

Comments
 (0)