Skip to content

Commit 137c36e

Browse files
MohsinHashmi-DataInnmohsin-wiserclaude
authored
fix(env): fix environment variables for coder and local devcontainer (#460)
* fix(env): fix environment variables for coder and local devcontainer This commit fixes critical environment variable issues that prevented proper database and Redis connectivity in Coder workspaces, and adds missing configuration for CORS and file uploads. Root Cause: - Coder template sets correct hostnames (db, redis) but .envrc was loading .devcontainer/.env which overwrote them with localhost - Frontend couldn't reach backend in Coder (localhost in browser != workspace) - Missing environment variables in validation and .env.example Changes: 1. Database & Redis Hostname Handling (.devcontainer/post-create.sh): - Enhanced .envrc generation to save Coder env vars BEFORE loading .env - Restore Coder values AFTER loading .env (preserves db/redis hostnames) - Added POSTGRES_HOST to saved/restored variables - Local devcontainer continues to use localhost (network_mode: service:db) 2. Frontend-Backend Communication (apps/frontend/vite.config.js): - Added Vite proxy configuration to forward API calls to backend - Uses relative URLs so proxy works in both Coder and local - Eliminates need for absolute URLs (http://localhost:8080) - Bypass logic for frontend routes and static assets 3. Environment Variable Completeness (.devcontainer/.env.example): - Added missing POSTGRES_HOST and POSTGRES_PORT - Added CORS_ALLOWED_ORIGINS with environment-aware defaults - Added FILE_UPLOAD_DIR for future file upload features - Comprehensive documentation for each variable 4. Validation (.devcontainer/setup-env.sh): - Added POSTGRES_HOST and POSTGRES_PORT to REQUIRED_VARS - Added SPRING_DATA_REDIS_HOST and SPRING_DATA_REDIS_PORT - Ensures all critical variables are validated on workspace creation 5. Coder Template (.coder/template.tf): - Added CORS_ALLOWED_ORIGINS=https://* for Coder workspaces - Added FILE_UPLOAD_DIR for consistent configuration - Maintains all existing Coder-specific variables 6. .envrc Validation (.devcontainer/post-create.sh): - Added validation check after .envrc generation - Provides early warning if .envrc creation fails Testing: After workspace recreation, verify environment variables are correct in both Coder (db, redis, https://*) and local (localhost, localhost, *) environments. Impact: - Database connectivity works in both Coder and local - Redis connectivity works in both environments - Frontend can reach backend in both environments - Environment-aware CORS configuration - Future-proof file upload directory configuration 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com> * chore: fix formatting for auto-generated config files * fix(vite,cors): fix spa routing and cors configuration Address PR review feedback: 1. Fix Vite proxy bypass to handle all SPA routes - Added explicit list of frontend routes (login, register, etc.) - Previously only handled / and /admin/* routes - Now direct navigation/refresh works on all SPA routes 2. Fix CORS configuration to use literal wildcard - Changed CORS_ALLOWED_ORIGINS from "https://*" to "*" - SimpleCorsFilter only treats literal "*" as wildcard - Pattern matching like "https://*" doesn't work (uses exact string match) - Updated Coder template, .env.example, and .envrc generation 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com> --------- Co-authored-by: Mohsin Hashmi <mhashmi@wiser.com> Co-authored-by: Claude Sonnet 4.5 <noreply@anthropic.com>
1 parent b2d9993 commit 137c36e

7 files changed

Lines changed: 417 additions & 2 deletions

File tree

.auto-claude-security.json

Lines changed: 230 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,230 @@
1+
{
2+
"base_commands": [
3+
".",
4+
"[",
5+
"[[",
6+
"ag",
7+
"awk",
8+
"basename",
9+
"bash",
10+
"bc",
11+
"break",
12+
"cat",
13+
"cd",
14+
"chmod",
15+
"clear",
16+
"cmp",
17+
"column",
18+
"comm",
19+
"command",
20+
"continue",
21+
"cp",
22+
"curl",
23+
"cut",
24+
"date",
25+
"df",
26+
"diff",
27+
"dig",
28+
"dirname",
29+
"du",
30+
"echo",
31+
"egrep",
32+
"env",
33+
"eval",
34+
"exec",
35+
"exit",
36+
"expand",
37+
"export",
38+
"expr",
39+
"false",
40+
"fd",
41+
"fgrep",
42+
"file",
43+
"find",
44+
"fmt",
45+
"fold",
46+
"gawk",
47+
"gh",
48+
"git",
49+
"grep",
50+
"gunzip",
51+
"gzip",
52+
"head",
53+
"help",
54+
"host",
55+
"iconv",
56+
"id",
57+
"jobs",
58+
"join",
59+
"jq",
60+
"kill",
61+
"killall",
62+
"less",
63+
"let",
64+
"ln",
65+
"ls",
66+
"lsof",
67+
"man",
68+
"mkdir",
69+
"mktemp",
70+
"more",
71+
"mv",
72+
"nl",
73+
"paste",
74+
"pgrep",
75+
"ping",
76+
"pkill",
77+
"popd",
78+
"printenv",
79+
"printf",
80+
"ps",
81+
"pushd",
82+
"pwd",
83+
"read",
84+
"readlink",
85+
"realpath",
86+
"reset",
87+
"return",
88+
"rev",
89+
"rg",
90+
"rm",
91+
"rmdir",
92+
"sed",
93+
"seq",
94+
"set",
95+
"sh",
96+
"shuf",
97+
"sleep",
98+
"sort",
99+
"source",
100+
"split",
101+
"stat",
102+
"tail",
103+
"tar",
104+
"tee",
105+
"test",
106+
"time",
107+
"timeout",
108+
"touch",
109+
"tr",
110+
"tree",
111+
"true",
112+
"type",
113+
"uname",
114+
"unexpand",
115+
"uniq",
116+
"unset",
117+
"unzip",
118+
"watch",
119+
"wc",
120+
"wget",
121+
"whereis",
122+
"which",
123+
"whoami",
124+
"xargs",
125+
"yes",
126+
"yq",
127+
"zip",
128+
"zsh"
129+
],
130+
"stack_commands": [
131+
"ant",
132+
"ar",
133+
"clang",
134+
"clang++",
135+
"cmake",
136+
"composer",
137+
"eslint",
138+
"g++",
139+
"gcc",
140+
"gradle",
141+
"gradlew",
142+
"ipython",
143+
"jar",
144+
"java",
145+
"javac",
146+
"jupyter",
147+
"k9s",
148+
"kubeadm",
149+
"kubectl",
150+
"kubectx",
151+
"kubens",
152+
"kubeseal",
153+
"kustomize",
154+
"ld",
155+
"make",
156+
"maven",
157+
"meson",
158+
"mvn",
159+
"ninja",
160+
"nm",
161+
"node",
162+
"notebook",
163+
"npm",
164+
"npx",
165+
"objdump",
166+
"pdb",
167+
"php",
168+
"pip",
169+
"pip3",
170+
"pipx",
171+
"prettier",
172+
"pudb",
173+
"python",
174+
"python3",
175+
"sbt",
176+
"scala",
177+
"scalac",
178+
"strip",
179+
"terraform",
180+
"terragrunt",
181+
"tflint",
182+
"tfsec",
183+
"ts-node",
184+
"tsc",
185+
"tsx"
186+
],
187+
"script_commands": ["bun", "npm", "pnpm", "yarn"],
188+
"custom_commands": [],
189+
"detected_stack": {
190+
"languages": ["python", "javascript", "typescript", "php", "java", "scala", "c"],
191+
"package_managers": ["npm"],
192+
"frameworks": ["eslint", "prettier"],
193+
"databases": [],
194+
"infrastructure": ["kubernetes", "terraform"],
195+
"cloud_providers": [],
196+
"code_quality_tools": [],
197+
"version_managers": []
198+
},
199+
"custom_scripts": {
200+
"npm_scripts": [
201+
"frontend",
202+
"frontend:build",
203+
"backend:build",
204+
"backend:run",
205+
"test",
206+
"test:frontend",
207+
"test:frontend:e2e",
208+
"test:frontend:e2e:auth",
209+
"test:frontend:e2e:registration",
210+
"test:frontend:e2e:reset-password",
211+
"test:backend",
212+
"lint",
213+
"format",
214+
"format:check",
215+
"pre-pr-check",
216+
"validate",
217+
"validate:frontend",
218+
"validate:backend",
219+
"fix",
220+
"prepare"
221+
],
222+
"make_targets": [],
223+
"poetry_scripts": [],
224+
"cargo_aliases": [],
225+
"shell_scripts": []
226+
},
227+
"project_dir": "/Users/moshinhashmi/github/SimpleAccounts-UAE",
228+
"created_at": "2026-01-03T20:15:47.759444",
229+
"project_hash": "f2d9508fb3b2791ecb12bb3571c63899"
230+
}

.claude_settings.json

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
{
2+
"sandbox": {
3+
"enabled": true,
4+
"autoAllowBashIfSandboxed": true
5+
},
6+
"permissions": {
7+
"defaultMode": "acceptEdits",
8+
"allow": [
9+
"Read(./**)",
10+
"Write(./**)",
11+
"Edit(./**)",
12+
"Glob(./**)",
13+
"Grep(./**)",
14+
"Read(/Users/moshinhashmi/github/SimpleAccounts-UAE/**)",
15+
"Write(/Users/moshinhashmi/github/SimpleAccounts-UAE/**)",
16+
"Edit(/Users/moshinhashmi/github/SimpleAccounts-UAE/**)",
17+
"Glob(/Users/moshinhashmi/github/SimpleAccounts-UAE/**)",
18+
"Grep(/Users/moshinhashmi/github/SimpleAccounts-UAE/**)",
19+
"Read(/Users/moshinhashmi/github/SimpleAccounts-UAE/.auto-claude/ideation/**)",
20+
"Write(/Users/moshinhashmi/github/SimpleAccounts-UAE/.auto-claude/ideation/**)",
21+
"Edit(/Users/moshinhashmi/github/SimpleAccounts-UAE/.auto-claude/ideation/**)",
22+
"Bash(*)",
23+
"WebFetch(*)",
24+
"WebSearch(*)",
25+
"mcp__context7__resolve-library-id(*)",
26+
"mcp__context7__get-library-docs(*)",
27+
"mcp__graphiti-memory__search_nodes(*)",
28+
"mcp__graphiti-memory__search_facts(*)",
29+
"mcp__graphiti-memory__add_episode(*)",
30+
"mcp__graphiti-memory__get_episodes(*)",
31+
"mcp__graphiti-memory__get_entity_edge(*)"
32+
]
33+
}
34+
}

.coder/template.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -418,6 +418,12 @@ resource "docker_container" "workspace" {
418418
"SPRING_DATA_REDIS_PORT=6379",
419419
# Application host
420420
"SIMPLEACCOUNTS_HOST=http://localhost:8080",
421+
# CORS configuration (allow all origins in dev environment)
422+
# Note: SimpleCorsFilter only treats literal "*" as wildcard (not pattern matching)
423+
# For production, this should be set to specific domain(s)
424+
"CORS_ALLOWED_ORIGINS=*",
425+
# File upload directory (for user uploads)
426+
"FILE_UPLOAD_DIR=/tmp/simpleaccounts-uploads",
421427
# Application settings
422428
"PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD=1",
423429
"PLAYWRIGHT_CHROMIUM_EXECUTABLE_PATH=/usr/bin/chromium",

.devcontainer/.env.example

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,25 @@
99
POSTGRES_USER=simpleaccounts
1010
POSTGRES_PASSWORD=simpleaccounts_dev
1111
POSTGRES_DB=simpleaccounts
12+
POSTGRES_HOST=localhost
13+
POSTGRES_PORT=5432
1214

1315
# =============================================================================
1416
# Backend Spring Boot Configuration
1517
# These variables are used by application.properties
16-
# Note: Use localhost because all services share network via network_mode: service:db
18+
# =============================================================================
19+
# IMPORTANT: Hostname resolution differs by environment:
20+
#
21+
# LOCAL DEVCONTAINER:
22+
# - Use 'localhost' because all services share network via network_mode: service:db
23+
# - The .envrc file will use these localhost values directly
24+
#
25+
# CODER WORKSPACES:
26+
# - Coder template sets SIMPLEACCOUNTS_DB_HOST=db and SPRING_DATA_REDIS_HOST=redis
27+
# - The .envrc file automatically preserves Coder's values and ignores localhost
28+
# - This happens via CODER_AGENT_TOKEN detection in .envrc
29+
#
30+
# TL;DR: Keep these as localhost - Coder environments override automatically
1731
# =============================================================================
1832
SIMPLEACCOUNTS_DB_HOST=localhost
1933
SIMPLEACCOUNTS_DB_PORT=5432
@@ -31,6 +45,25 @@ SPRING_DATA_REDIS_PORT=6379
3145
# Application Host
3246
SIMPLEACCOUNTS_HOST=http://localhost:8080
3347

48+
# =============================================================================
49+
# CORS Configuration
50+
# =============================================================================
51+
# SimpleCorsFilter only treats literal "*" as wildcard (not pattern matching)
52+
# For development (local and Coder), use "*" to allow all origins
53+
# For production, this should be set to specific domain(s) (comma-separated)
54+
# Examples:
55+
# Development: CORS_ALLOWED_ORIGINS=*
56+
# Production: CORS_ALLOWED_ORIGINS=https://app.example.com,https://www.example.com
57+
CORS_ALLOWED_ORIGINS=*
58+
59+
# =============================================================================
60+
# File Upload Configuration
61+
# =============================================================================
62+
# Directory for user file uploads (if feature is implemented)
63+
# Defaults to /tmp/simpleaccounts-uploads if not set
64+
# Note: Currently the app only reads sample files from classpath
65+
FILE_UPLOAD_DIR=/tmp/simpleaccounts-uploads
66+
3467
# =============================================================================
3568
# SonarQube (for MCP)
3669
# =============================================================================

0 commit comments

Comments
 (0)