Skip to content

Commit a444e13

Browse files
authored
Local emulator fixes (stack-auth#437)
1 parent be05819 commit a444e13

File tree

5 files changed

+33
-30
lines changed

5 files changed

+33
-30
lines changed

apps/backend/prisma/seed.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -494,7 +494,7 @@ async function seed() {
494494
connect: {
495495
projectConfigId_id: {
496496
id,
497-
projectConfigId: (internalProject as any).configId,
497+
projectConfigId: emulatorProject.configId,
498498
}
499499
}
500500
}

apps/dashboard/src/app/(main)/(protected)/projects/[projectId]/emails/page-client.tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,13 @@ export default function PageClient() {
3232
{getPublicEnvVar('NEXT_PUBLIC_STACK_EMULATOR_ENABLED') === 'true' ? (
3333
<SettingCard
3434
title="Mock Emails"
35-
description="All the emails that are sent in the emulator will land here"
35+
description="View all emails sent through the emulator in Inbucket"
3636
>
37-
<iframe
38-
src="http://localhost:32203"
39-
className="w-full h-[600px] border border-gray-200 rounded-md"
40-
title="Mock Email Inbox"
41-
/>
37+
<Button variant='secondary' onClick={() => {
38+
window.open(getPublicEnvVar('NEXT_PUBLIC_STACK_INBUCKET_WEB_URL') + '/monitor', '_blank');
39+
}}>
40+
Open Inbox
41+
</Button>
4242
</SettingCard>
4343
) : (
4444
<SettingCard

docker/emulator/docker.compose.yaml

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ services:
3232
NEXT_PUBLIC_STACK_SVIX_SERVER_URL: http://localhost:32201
3333
STACK_SVIX_SERVER_URL: http://svix-server:8071
3434
STACK_SVIX_API_KEY: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpYXQiOjE2NTUxNDA2MzksImV4cCI6MTk3MDUwMDYzOSwibmJmIjoxNjU1MTQwNjM5LCJpc3MiOiJzdml4LXNlcnZlciIsInN1YiI6Im9yZ18yM3JiOFlkR3FNVDBxSXpwZ0d3ZFhmSGlyTXUifQ.En8w77ZJWbd0qrMlHHupHUB-4cx17RfzFykseg95SUk
35+
NEXT_PUBLIC_STACK_INBUCKET_WEB_URL: http://localhost:32203
3536
STACK_EMAIL_HOST: inbucket
3637
STACK_EMAIL_PORT: 2500
3738
STACK_EMAIL_SECURE: false
@@ -76,20 +77,10 @@ services:
7677
# ================= Inbucket =================
7778
inbucket:
7879
image: inbucket/inbucket:latest
79-
expose:
80-
- 9000
81-
volumes:
82-
- inbucket-data:/data
83-
84-
# inbucket proxy to allow iframe embedding
85-
inbucket-proxy:
86-
image: nginx:alpine
8780
ports:
88-
- 32203:80
81+
- 32203:9000
8982
volumes:
90-
- ./inbucket-nginx.conf:/etc/nginx/conf.d/default.conf
91-
depends_on:
92-
- inbucket
83+
- inbucket-data:/data
9384

9485
# ================= Svix =================
9586

docker/server/entrypoint.sh

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -43,29 +43,39 @@ else
4343
cd ../..
4444
fi
4545

46-
# Find all sentinel values and replace them with corresponding env vars
47-
unhandled_sentinels=$(find /app/apps -type f -exec grep -l "STACK_ENV_VAR_SENTINEL" {} + | xargs grep -h "STACK_ENV_VAR_SENTINEL" | grep -o "STACK_ENV_VAR_SENTINEL[^\"']*" | tr -d '\\' | sort -u | grep -v "^STACK_ENV_VAR_SENTINEL$")
46+
# Find all files in /app/apps that contain a STACK_ENV_VAR_SENTINEL and extract the unique sentinel strings.
47+
unhandled_sentinels=$(find /app/apps -type f -exec grep -l "STACK_ENV_VAR_SENTINEL" {} + | \
48+
xargs grep -h "STACK_ENV_VAR_SENTINEL" | \
49+
grep -o "STACK_ENV_VAR_SENTINEL[A-Z_]*" | \
50+
sort -u | grep -v "^STACK_ENV_VAR_SENTINEL$")
51+
52+
# Choose an uncommon delimiter – here, we use the ASCII Unit Separator (0x1F)
53+
delimiter=$(printf '\037')
4854

4955
for sentinel in $unhandled_sentinels; do
50-
# Extract the suffix after STACK_ENV_VAR_SENTINEL_
56+
# The sentinel is like "STACK_ENV_VAR_SENTINEL_MY_VAR", so extract the env var name.
5157
env_var=${sentinel#STACK_ENV_VAR_SENTINEL_}
5258

53-
# Get the corresponding environment variable value
59+
# Get the corresponding environment variable value.
5460
value="${!env_var}"
5561

56-
# Skip if env var is not set
62+
# If the env var is not set, skip replacement.
5763
if [ -z "$value" ]; then
5864
continue
5965
fi
6066

61-
# Escape special characters in both sentinel and value
62-
escaped_sentinel=$(printf '%s\n' "$sentinel" | sed 's/[[\.*^$/]/\\&/g')
63-
escaped_value=$(printf '%s\n' "$value" | sed 's/[[\.*^$/]/\\&/g')
64-
65-
# Replace the sentinel with the value
66-
find /app/apps -type f -exec sed -i "s/$escaped_sentinel/$escaped_value/g" {} +
67+
# Although the sentinel only contains [A-Z_] we still escape it for any regex meta-characters.
68+
escaped_sentinel=$(printf '%s\n' "$sentinel" | sed -e 's/\\/\\\\/g' -e 's/[][\/.^$*]/\\&/g')
69+
70+
# For the replacement value, first escape backslashes, then escape any occurrence of
71+
# the chosen delimiter and the '&' (which has special meaning in sed replacements).
72+
escaped_value=$(printf '%s\n' "$value" | sed -e 's/\\/\\\\/g' -e "s/[${delimiter}&]/\\\\&/g")
73+
74+
# Now replace the sentinel with the (properly escaped) value in all files.
75+
find /app/apps -type f -exec sed -i "s${delimiter}${escaped_sentinel}${delimiter}${escaped_value}${delimiter}g" {} +
6776
done
6877

78+
6979
# Start backend and dashboard in parallel
7080
echo "Starting backend on port $BACKEND_PORT..."
7181
PORT=$BACKEND_PORT HOSTNAME=0.0.0.0 node apps/backend/server.js &

packages/stack-shared/src/utils/env.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ const _inlineEnvVars = {
8888
NEXT_PUBLIC_STACK_PROJECT_ID: process.env.NEXT_PUBLIC_STACK_PROJECT_ID,
8989
NEXT_PUBLIC_STACK_PUBLISHABLE_CLIENT_KEY: process.env.NEXT_PUBLIC_STACK_PUBLISHABLE_CLIENT_KEY,
9090
NEXT_PUBLIC_STACK_URL: process.env.NEXT_PUBLIC_STACK_URL,
91+
NEXT_PUBLIC_STACK_INBUCKET_WEB_URL: process.env.NEXT_PUBLIC_STACK_INBUCKET_WEB_URL,
9192
} as const;
9293

9394
// This will be replaced with the actual env vars after a docker build
@@ -111,6 +112,7 @@ const _postBuildEnvVars = {
111112
NEXT_PUBLIC_STACK_EMULATOR_PROJECT_ID: "STACK_ENV_VAR_SENTINEL_NEXT_PUBLIC_STACK_EMULATOR_PROJECT_ID",
112113
NEXT_PUBLIC_STACK_PUBLISHABLE_CLIENT_KEY: "STACK_ENV_VAR_SENTINEL_NEXT_PUBLIC_STACK_PUBLISHABLE_CLIENT_KEY",
113114
NEXT_PUBLIC_STACK_URL: "STACK_ENV_VAR_SENTINEL_NEXT_PUBLIC_STACK_URL",
115+
NEXT_PUBLIC_STACK_INBUCKET_WEB_URL: "STACK_ENV_VAR_SENTINEL_NEXT_PUBLIC_STACK_INBUCKET_WEB_URL",
114116
} satisfies typeof _inlineEnvVars;
115117

116118
// If this is not replaced with "true", then we will not use inline env vars

0 commit comments

Comments
 (0)