Skip to content

Commit 02aff3a

Browse files
nullcoderclaude
andauthored
docs: clarify environment variable usage and add .env.production (#141)
- Add .env.production with clear warnings about not putting secrets - Update documentation to explain build-time vs runtime variables - Emphasize that .env files are for NEXT_PUBLIC_* variables only - Clarify that secrets must use .dev.vars locally or wrangler secrets in production - Add warnings throughout docs to prevent accidental secret exposure This helps prevent developers from accidentally exposing secrets in the client bundle by putting them in .env or .env.production files. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-authored-by: Claude <noreply@anthropic.com>
1 parent 0fe8158 commit 02aff3a

File tree

4 files changed

+60
-11
lines changed

4 files changed

+60
-11
lines changed

.env.production

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Production build-time environment variables
2+
# IMPORTANT: This file is used during the build process only
3+
# DO NOT put any secrets here - they would be exposed in the client bundle
4+
# Only NEXT_PUBLIC_* variables should go here as they are meant to be public
5+
# For secrets, use Cloudflare Workers secrets via 'wrangler secret put'
6+
7+
# Turnstile site key for production
8+
NEXT_PUBLIC_TURNSTILE_SITE_KEY=0x4AAAAAABgaxmj8dZ-K1EyE

README.md

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,12 +155,24 @@ bucket_name = "ghostpaste-bucket"
155155
NEXT_PUBLIC_APP_URL = "https://ghostpaste.dev"
156156
```
157157

158-
For local development secrets, create `.dev.vars`:
158+
For environment variables:
159159

160+
**Build-time variables** (`.env` or `.env.production`):
161+
162+
```bash
163+
# Only NEXT_PUBLIC_* variables - these are embedded in the client bundle
164+
NEXT_PUBLIC_TURNSTILE_SITE_KEY=your_public_site_key
160165
```
161-
# Any additional secrets go here
166+
167+
**Runtime secrets** (`.dev.vars` for local, `wrangler secret put` for production):
168+
169+
```bash
170+
# Never put these in .env files!
171+
TURNSTILE_SECRET_KEY=your_secret_key
162172
```
163173

174+
⚠️ **Important**: Never put secrets in `.env` or `.env.production` files as they become part of the client bundle!
175+
164176
### Deployment
165177

166178
```bash

docs/LOCAL_DEVELOPMENT.md

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,33 @@ This guide explains how to set up and run GhostPaste locally for development.
2424
```
2525

2626
3. **Set up local environment variables**
27-
Create a `.dev.vars` file in the root directory:
27+
28+
GhostPaste uses different environment files for different purposes:
29+
30+
- **`.env`** - Build-time variables for local development (loaded by Next.js during build)
31+
- **`.env.production`** - Build-time variables for production builds (PUBLIC variables only - NO SECRETS!)
32+
- **`.dev.vars`** - Runtime secrets for local Wrangler development
33+
- **Cloudflare Secrets** - Runtime secrets for production (via `wrangler secret put`)
34+
35+
Create these files as needed:
36+
37+
**`.env`** (for local build-time variables):
38+
2839
```bash
29-
# Local development secrets
30-
# Add any local development secrets here
31-
# Example:
32-
# API_SECRET=your-secret-here
40+
# Public variables that are safe to expose in the client bundle
41+
NEXT_PUBLIC_TURNSTILE_SITE_KEY=1x00000000000000000000AA
3342
```
3443

44+
**`.dev.vars`** (for local runtime secrets):
45+
46+
```bash
47+
# Runtime secrets - these are NOT exposed to the client
48+
TURNSTILE_SECRET_KEY=1x0000000000000000000000000000000AA
49+
# Add other local development secrets here
50+
```
51+
52+
**Important**: Never put secrets in `.env` or `.env.production` files as they are embedded in the client bundle during build!
53+
3554
## Development Workflows
3655

3756
### Standard Next.js Development
@@ -106,8 +125,9 @@ When using `npm run preview`, the following services are simulated locally:
106125

107126
### Environment Variables
108127

109-
- Development environment uses `env.development` from `wrangler.toml`
110-
- Secrets loaded from `.dev.vars` file
128+
- Build-time variables (NEXT*PUBLIC*\*) loaded from `.env` during build
129+
- Runtime environment uses `env.development` from `wrangler.toml`
130+
- Runtime secrets loaded from `.dev.vars` file
111131
- `ENVIRONMENT=development` and `NEXT_PUBLIC_APP_URL=http://localhost:3000`
112132

113133
## Debugging

docs/TURNSTILE_SETUP.md

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,14 +47,23 @@ TURNSTILE_SECRET_KEY=1x0000000000000000000000000000000AA
4747

4848
#### Production (Cloudflare Workers)
4949

50-
1. Update `wrangler.toml` with the public site key:
50+
1. For production builds, create `.env.production`:
51+
52+
```bash
53+
# IMPORTANT: Only put PUBLIC variables here - NO SECRETS!
54+
NEXT_PUBLIC_TURNSTILE_SITE_KEY=your_site_key_here
55+
```
56+
57+
**Warning**: `.env.production` is used at build time and variables are embedded in the client bundle. Never put secret keys here!
58+
59+
2. Alternatively, update `wrangler.toml` with the public site key:
5160

5261
```toml
5362
[vars]
5463
NEXT_PUBLIC_TURNSTILE_SITE_KEY = "your_site_key_here"
5564
```
5665

57-
2. Set the secret key as a Cloudflare secret:
66+
3. Set the secret key as a Cloudflare secret:
5867

5968
```bash
6069
wrangler secret put TURNSTILE_SECRET_KEY

0 commit comments

Comments
 (0)