create-fluxstack 1.0.13 → 1.0.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.env.example +29 -29
- package/app/client/README.md +69 -69
- package/app/client/index.html +14 -13
- package/app/client/src/App.tsx +157 -524
- package/app/client/src/components/ErrorBoundary.tsx +107 -0
- package/app/client/src/components/ErrorDisplay.css +365 -0
- package/app/client/src/components/ErrorDisplay.tsx +258 -0
- package/app/client/src/components/FluxStackConfig.tsx +1321 -0
- package/app/client/src/components/HybridLiveCounter.tsx +140 -0
- package/app/client/src/components/LiveClock.tsx +286 -0
- package/app/client/src/components/MainLayout.tsx +390 -0
- package/app/client/src/components/SidebarNavigation.tsx +391 -0
- package/app/client/src/components/StateDemo.tsx +178 -0
- package/app/client/src/components/SystemMonitor.tsx +1038 -0
- package/app/client/src/components/Teste.tsx +104 -0
- package/app/client/src/components/UserProfile.tsx +809 -0
- package/app/client/src/hooks/useAuth.ts +39 -0
- package/app/client/src/hooks/useNotifications.ts +56 -0
- package/app/client/src/lib/eden-api.ts +189 -53
- package/app/client/src/lib/errors.ts +340 -0
- package/app/client/src/lib/hooks/useErrorHandler.ts +258 -0
- package/app/client/src/lib/index.ts +45 -0
- package/app/client/src/main.tsx +3 -2
- package/app/client/src/pages/ApiDocs.tsx +182 -0
- package/app/client/src/pages/Demo.tsx +174 -0
- package/app/client/src/pages/HybridLive.tsx +263 -0
- package/app/client/src/pages/Overview.tsx +155 -0
- package/app/client/src/store/README.md +43 -0
- package/app/client/src/store/index.ts +16 -0
- package/app/client/src/store/slices/uiSlice.ts +151 -0
- package/app/client/src/store/slices/userSlice.ts +161 -0
- package/app/client/src/test/README.md +257 -0
- package/app/client/src/test/setup.ts +70 -0
- package/app/client/src/test/types.ts +12 -0
- package/app/client/src/vite-env.d.ts +1 -1
- package/app/client/tsconfig.app.json +44 -43
- package/app/client/tsconfig.json +7 -7
- package/app/client/tsconfig.node.json +25 -25
- package/app/client/zustand-setup.md +65 -0
- package/app/server/controllers/users.controller.ts +68 -68
- package/app/server/index.ts +9 -1
- package/app/server/live/CounterComponent.ts +191 -0
- package/app/server/live/FluxStackConfig.ts +529 -0
- package/app/server/live/LiveClockComponent.ts +214 -0
- package/app/server/live/SidebarNavigation.ts +156 -0
- package/app/server/live/SystemMonitor.ts +594 -0
- package/app/server/live/SystemMonitorIntegration.ts +151 -0
- package/app/server/live/TesteComponent.ts +87 -0
- package/app/server/live/UserProfileComponent.ts +135 -0
- package/app/server/live/register-components.ts +28 -0
- package/app/server/middleware/auth.ts +136 -0
- package/app/server/middleware/errorHandling.ts +250 -0
- package/app/server/middleware/index.ts +10 -0
- package/app/server/middleware/rateLimit.ts +193 -0
- package/app/server/middleware/requestLogging.ts +215 -0
- package/app/server/middleware/validation.ts +270 -0
- package/app/server/routes/index.ts +14 -2
- package/app/server/routes/upload.ts +92 -0
- package/app/server/routes/users.routes.ts +2 -9
- package/app/server/services/NotificationService.ts +302 -0
- package/app/server/services/UserService.ts +222 -0
- package/app/server/services/index.ts +46 -0
- package/core/cli/commands/plugin-deps.ts +263 -0
- package/core/cli/generators/README.md +339 -0
- package/core/cli/generators/component.ts +770 -0
- package/core/cli/generators/controller.ts +299 -0
- package/core/cli/generators/index.ts +144 -0
- package/core/cli/generators/interactive.ts +228 -0
- package/core/cli/generators/prompts.ts +83 -0
- package/core/cli/generators/route.ts +513 -0
- package/core/cli/generators/service.ts +465 -0
- package/core/cli/generators/template-engine.ts +154 -0
- package/core/cli/generators/types.ts +71 -0
- package/core/cli/generators/utils.ts +192 -0
- package/core/cli/index.ts +69 -0
- package/core/cli/plugin-discovery.ts +16 -85
- package/core/client/fluxstack.ts +17 -0
- package/core/client/hooks/index.ts +7 -0
- package/core/client/hooks/state-validator.ts +130 -0
- package/core/client/hooks/useAuth.ts +49 -0
- package/core/client/hooks/useChunkedUpload.ts +258 -0
- package/core/client/hooks/useHybridLiveComponent.ts +967 -0
- package/core/client/hooks/useWebSocket.ts +373 -0
- package/core/client/index.ts +47 -0
- package/core/client/state/createStore.ts +193 -0
- package/core/client/state/index.ts +15 -0
- package/core/config/env-dynamic.ts +1 -1
- package/core/config/env.ts +2 -1
- package/core/config/runtime-config.ts +3 -3
- package/core/config/schema.ts +84 -49
- package/core/framework/server.ts +30 -0
- package/core/index.ts +25 -0
- package/core/live/ComponentRegistry.ts +399 -0
- package/core/live/types.ts +164 -0
- package/core/plugins/built-in/live-components/commands/create-live-component.ts +1201 -0
- package/core/plugins/built-in/live-components/index.ts +27 -0
- package/core/plugins/built-in/logger/index.ts +1 -1
- package/core/plugins/built-in/monitoring/index.ts +1 -1
- package/core/plugins/built-in/static/index.ts +1 -1
- package/core/plugins/built-in/swagger/index.ts +1 -1
- package/core/plugins/built-in/vite/index.ts +1 -1
- package/core/plugins/dependency-manager.ts +384 -0
- package/core/plugins/index.ts +5 -1
- package/core/plugins/manager.ts +7 -3
- package/core/plugins/registry.ts +88 -10
- package/core/plugins/types.ts +11 -11
- package/core/server/framework.ts +43 -0
- package/core/server/index.ts +11 -1
- package/core/server/live/ComponentRegistry.ts +1017 -0
- package/core/server/live/FileUploadManager.ts +272 -0
- package/core/server/live/LiveComponentPerformanceMonitor.ts +930 -0
- package/core/server/live/SingleConnectionManager.ts +0 -0
- package/core/server/live/StateSignature.ts +644 -0
- package/core/server/live/WebSocketConnectionManager.ts +688 -0
- package/core/server/live/websocket-plugin.ts +435 -0
- package/core/server/middleware/errorHandling.ts +141 -0
- package/core/server/middleware/index.ts +16 -0
- package/core/server/plugins/static-files-plugin.ts +232 -0
- package/core/server/services/BaseService.ts +95 -0
- package/core/server/services/ServiceContainer.ts +144 -0
- package/core/server/services/index.ts +9 -0
- package/core/templates/create-project.ts +196 -33
- package/core/testing/index.ts +10 -0
- package/core/testing/setup.ts +74 -0
- package/core/types/build.ts +38 -14
- package/core/types/types.ts +319 -0
- package/core/utils/env-runtime.ts +7 -0
- package/core/utils/errors/handlers.ts +264 -39
- package/core/utils/errors/index.ts +528 -18
- package/core/utils/errors/middleware.ts +114 -0
- package/core/utils/logger/formatters.ts +222 -0
- package/core/utils/logger/index.ts +167 -48
- package/core/utils/logger/middleware.ts +253 -0
- package/core/utils/logger/performance.ts +384 -0
- package/core/utils/logger/transports.ts +365 -0
- package/create-fluxstack.ts +296 -296
- package/fluxstack.config.ts +17 -1
- package/package-template.json +66 -66
- package/package.json +31 -6
- package/public/README.md +16 -0
- package/vite.config.ts +29 -14
- package/.claude/settings.local.json +0 -74
- package/.github/workflows/ci-build-tests.yml +0 -480
- package/.github/workflows/dependency-management.yml +0 -324
- package/.github/workflows/release-validation.yml +0 -355
- package/.kiro/specs/fluxstack-architecture-optimization/design.md +0 -700
- package/.kiro/specs/fluxstack-architecture-optimization/requirements.md +0 -127
- package/.kiro/specs/fluxstack-architecture-optimization/tasks.md +0 -330
- package/CLAUDE.md +0 -200
- package/Dockerfile +0 -58
- package/Dockerfile.backend +0 -52
- package/Dockerfile.frontend +0 -54
- package/README-Docker.md +0 -85
- package/ai-context/00-QUICK-START.md +0 -86
- package/ai-context/README.md +0 -88
- package/ai-context/development/eden-treaty-guide.md +0 -362
- package/ai-context/development/patterns.md +0 -382
- package/ai-context/development/plugins-guide.md +0 -572
- package/ai-context/examples/crud-complete.md +0 -626
- package/ai-context/project/architecture.md +0 -399
- package/ai-context/project/overview.md +0 -213
- package/ai-context/recent-changes/eden-treaty-refactor.md +0 -281
- package/ai-context/recent-changes/type-inference-fix.md +0 -223
- package/ai-context/reference/environment-vars.md +0 -384
- package/ai-context/reference/troubleshooting.md +0 -407
- package/app/client/src/components/TestPage.tsx +0 -453
- package/bun.lock +0 -1063
- package/bunfig.toml +0 -16
- package/core/__tests__/integration.test.ts +0 -227
- package/core/build/index.ts +0 -186
- package/core/config/__tests__/config-loader.test.ts +0 -554
- package/core/config/__tests__/config-merger.test.ts +0 -657
- package/core/config/__tests__/env-converter.test.ts +0 -372
- package/core/config/__tests__/env-processor.test.ts +0 -431
- package/core/config/__tests__/env.test.ts +0 -452
- package/core/config/__tests__/integration.test.ts +0 -418
- package/core/config/__tests__/loader.test.ts +0 -331
- package/core/config/__tests__/schema.test.ts +0 -129
- package/core/config/__tests__/validator.test.ts +0 -318
- package/core/framework/__tests__/server.test.ts +0 -233
- package/core/plugins/__tests__/built-in.test.ts.disabled +0 -366
- package/core/plugins/__tests__/manager.test.ts +0 -398
- package/core/plugins/__tests__/monitoring.test.ts +0 -401
- package/core/plugins/__tests__/registry.test.ts +0 -335
- package/core/utils/__tests__/errors.test.ts +0 -139
- package/core/utils/__tests__/helpers.test.ts +0 -297
- package/core/utils/__tests__/logger.test.ts +0 -141
- package/create-test-app.ts +0 -156
- package/docker-compose.microservices.yml +0 -75
- package/docker-compose.simple.yml +0 -57
- package/docker-compose.yml +0 -71
- package/eslint.config.js +0 -23
- package/flux-cli.ts +0 -214
- package/nginx-lb.conf +0 -37
- package/publish.sh +0 -63
- package/run-clean.ts +0 -26
- package/run-env-tests.ts +0 -313
- package/tailwind.config.js +0 -34
- package/tests/__mocks__/api.ts +0 -56
- package/tests/fixtures/users.ts +0 -69
- package/tests/integration/api/users.routes.test.ts +0 -221
- package/tests/setup.ts +0 -29
- package/tests/unit/app/client/App-simple.test.tsx +0 -56
- package/tests/unit/app/client/App.test.tsx.skip +0 -237
- package/tests/unit/app/client/eden-api.test.ts +0 -186
- package/tests/unit/app/client/simple.test.tsx +0 -23
- package/tests/unit/app/controllers/users.controller.test.ts +0 -150
- package/tests/unit/core/create-project.test.ts.skip +0 -95
- package/tests/unit/core/framework.test.ts +0 -144
- package/tests/unit/core/plugins/logger.test.ts.skip +0 -268
- package/tests/unit/core/plugins/vite.test.ts.disabled +0 -188
- package/tests/utils/test-helpers.ts +0 -61
- package/vitest.config.ts +0 -50
- package/workspace.json +0 -6
|
@@ -1,384 +0,0 @@
|
|
|
1
|
-
# 🌐 Environment Variables - FluxStack
|
|
2
|
-
|
|
3
|
-
> **Guia completo de variáveis de ambiente**: configuração, precedência e testing
|
|
4
|
-
|
|
5
|
-
## 🎯 **Sistema de Environment Variables**
|
|
6
|
-
|
|
7
|
-
O FluxStack utiliza um **sistema dinâmico** de environment variables com precedência clara e validação automática.
|
|
8
|
-
|
|
9
|
-
### **📋 Precedência (Maior → Menor)**
|
|
10
|
-
1. **Process env** (`process.env.VAR`)
|
|
11
|
-
2. **Runtime vars** (definidas em runtime)
|
|
12
|
-
3. **`.env` file** (carregado automaticamente)
|
|
13
|
-
4. **Default values** (valores padrão)
|
|
14
|
-
|
|
15
|
-
## 🔧 **Variáveis Principais**
|
|
16
|
-
|
|
17
|
-
### **🚀 Servidor (Backend)**
|
|
18
|
-
```bash
|
|
19
|
-
# Porta do servidor
|
|
20
|
-
PORT=3000 # Default: 3000
|
|
21
|
-
|
|
22
|
-
# Ambiente de execução
|
|
23
|
-
NODE_ENV=development # Options: development, production, test
|
|
24
|
-
|
|
25
|
-
# Host/endereço
|
|
26
|
-
HOST=localhost # Default: localhost
|
|
27
|
-
API_PREFIX=/api # Default: /api
|
|
28
|
-
|
|
29
|
-
# Database (quando configurado)
|
|
30
|
-
DATABASE_URL=postgresql://...
|
|
31
|
-
REDIS_URL=redis://...
|
|
32
|
-
|
|
33
|
-
# Secrets
|
|
34
|
-
JWT_SECRET=your-secret-here
|
|
35
|
-
API_KEY=your-api-key
|
|
36
|
-
```
|
|
37
|
-
|
|
38
|
-
### **⚛️ Frontend (Client)**
|
|
39
|
-
```bash
|
|
40
|
-
# Vite variables (VITE_ prefix obrigatório)
|
|
41
|
-
VITE_API_URL=http://localhost:3000
|
|
42
|
-
VITE_APP_NAME=FluxStack
|
|
43
|
-
VITE_APP_VERSION=1.5.0
|
|
44
|
-
VITE_NODE_ENV=development
|
|
45
|
-
|
|
46
|
-
# Build-specific
|
|
47
|
-
VITE_BUILD_TARGET=browser
|
|
48
|
-
VITE_BASE_URL=/
|
|
49
|
-
```
|
|
50
|
-
|
|
51
|
-
### **🧪 Testing**
|
|
52
|
-
```bash
|
|
53
|
-
# Test environment
|
|
54
|
-
NODE_ENV=test
|
|
55
|
-
TEST_PORT=3001
|
|
56
|
-
TEST_DB_URL=sqlite::memory:
|
|
57
|
-
|
|
58
|
-
# Test flags
|
|
59
|
-
SKIP_AUTH_TESTS=false
|
|
60
|
-
MOCK_EXTERNAL_APIS=true
|
|
61
|
-
```
|
|
62
|
-
|
|
63
|
-
### **🐳 Docker**
|
|
64
|
-
```bash
|
|
65
|
-
# Docker-specific
|
|
66
|
-
DOCKERFILE_TARGET=production
|
|
67
|
-
DOCKER_PORT=3000
|
|
68
|
-
DOCKER_ENV=production
|
|
69
|
-
|
|
70
|
-
# Multi-stage build
|
|
71
|
-
BUILD_STAGE=build
|
|
72
|
-
RUN_STAGE=runtime
|
|
73
|
-
```
|
|
74
|
-
|
|
75
|
-
## 📁 **Arquivo .env**
|
|
76
|
-
|
|
77
|
-
### **📝 Exemplo Completo (.env)**
|
|
78
|
-
```bash
|
|
79
|
-
# ===========================================
|
|
80
|
-
# FluxStack Environment Configuration
|
|
81
|
-
# ===========================================
|
|
82
|
-
|
|
83
|
-
# Server Configuration
|
|
84
|
-
PORT=3000
|
|
85
|
-
HOST=localhost
|
|
86
|
-
NODE_ENV=development
|
|
87
|
-
API_PREFIX=/api
|
|
88
|
-
|
|
89
|
-
# Frontend Configuration (Vite)
|
|
90
|
-
VITE_API_URL=http://localhost:3000
|
|
91
|
-
VITE_APP_NAME="FluxStack Development"
|
|
92
|
-
VITE_APP_VERSION=1.5.0
|
|
93
|
-
VITE_NODE_ENV=development
|
|
94
|
-
|
|
95
|
-
# Development Tools
|
|
96
|
-
DEBUG=true
|
|
97
|
-
LOG_LEVEL=info
|
|
98
|
-
HOT_RELOAD=true
|
|
99
|
-
|
|
100
|
-
# Database (example - configure as needed)
|
|
101
|
-
# DATABASE_URL=postgresql://user:pass@localhost:5432/fluxstack
|
|
102
|
-
# REDIS_URL=redis://localhost:6379
|
|
103
|
-
|
|
104
|
-
# Security (NEVER commit real secrets!)
|
|
105
|
-
# JWT_SECRET=your-super-secret-key-here-min-32-chars
|
|
106
|
-
# API_KEY=your-api-key-here
|
|
107
|
-
|
|
108
|
-
# Testing
|
|
109
|
-
TEST_DATABASE_URL=sqlite::memory:
|
|
110
|
-
MOCK_APIS=true
|
|
111
|
-
|
|
112
|
-
# Build Configuration
|
|
113
|
-
BUILD_TARGET=development
|
|
114
|
-
OPTIMIZE_BUNDLE=false
|
|
115
|
-
SOURCE_MAPS=true
|
|
116
|
-
```
|
|
117
|
-
|
|
118
|
-
### **📝 Produção (.env.production)**
|
|
119
|
-
```bash
|
|
120
|
-
# Production Environment
|
|
121
|
-
NODE_ENV=production
|
|
122
|
-
PORT=3000
|
|
123
|
-
HOST=0.0.0.0
|
|
124
|
-
|
|
125
|
-
# Security
|
|
126
|
-
JWT_SECRET=${JWT_SECRET} # From environment
|
|
127
|
-
API_KEY=${API_KEY} # From environment
|
|
128
|
-
|
|
129
|
-
# Performance
|
|
130
|
-
OPTIMIZE_BUNDLE=true
|
|
131
|
-
SOURCE_MAPS=false
|
|
132
|
-
LOG_LEVEL=warn
|
|
133
|
-
|
|
134
|
-
# Database
|
|
135
|
-
DATABASE_URL=${DATABASE_URL}
|
|
136
|
-
REDIS_URL=${REDIS_URL}
|
|
137
|
-
|
|
138
|
-
# Frontend
|
|
139
|
-
VITE_API_URL=https://api.yourapp.com
|
|
140
|
-
VITE_APP_NAME="FluxStack"
|
|
141
|
-
VITE_NODE_ENV=production
|
|
142
|
-
```
|
|
143
|
-
|
|
144
|
-
## 🔍 **Validação e Testing**
|
|
145
|
-
|
|
146
|
-
### **✅ Verificar Environment Variables**
|
|
147
|
-
```bash
|
|
148
|
-
# Comando built-in
|
|
149
|
-
bun run env-test
|
|
150
|
-
|
|
151
|
-
# Manual check
|
|
152
|
-
curl http://localhost:3000/api/env-test
|
|
153
|
-
```
|
|
154
|
-
|
|
155
|
-
### **✅ Testing Script**
|
|
156
|
-
```bash
|
|
157
|
-
# Script de teste (run-env-tests.ts)
|
|
158
|
-
#!/usr/bin/env bun
|
|
159
|
-
|
|
160
|
-
import { env } from 'bun'
|
|
161
|
-
|
|
162
|
-
console.log('🧪 Environment Variables Test')
|
|
163
|
-
console.log('============================')
|
|
164
|
-
|
|
165
|
-
// Test server vars
|
|
166
|
-
console.log(`PORT: ${env.PORT || 'undefined'}`)
|
|
167
|
-
console.log(`NODE_ENV: ${env.NODE_ENV || 'undefined'}`)
|
|
168
|
-
console.log(`HOST: ${env.HOST || 'undefined'}`)
|
|
169
|
-
|
|
170
|
-
// Test frontend vars
|
|
171
|
-
console.log(`VITE_API_URL: ${env.VITE_API_URL || 'undefined'}`)
|
|
172
|
-
console.log(`VITE_APP_NAME: ${env.VITE_APP_NAME || 'undefined'}`)
|
|
173
|
-
|
|
174
|
-
// Test precedence
|
|
175
|
-
env.TEST_VAR = 'runtime-value'
|
|
176
|
-
console.log(`Runtime test: ${env.TEST_VAR}`)
|
|
177
|
-
```
|
|
178
|
-
|
|
179
|
-
## 🛠️ **Configuração por Ambiente**
|
|
180
|
-
|
|
181
|
-
### **🔧 Development**
|
|
182
|
-
```bash
|
|
183
|
-
# .env.development
|
|
184
|
-
NODE_ENV=development
|
|
185
|
-
DEBUG=true
|
|
186
|
-
HOT_RELOAD=true
|
|
187
|
-
LOG_LEVEL=debug
|
|
188
|
-
|
|
189
|
-
# Frontend dev
|
|
190
|
-
VITE_API_URL=http://localhost:3000
|
|
191
|
-
VITE_APP_NAME="FluxStack [DEV]"
|
|
192
|
-
```
|
|
193
|
-
|
|
194
|
-
### **🧪 Testing**
|
|
195
|
-
```bash
|
|
196
|
-
# .env.test
|
|
197
|
-
NODE_ENV=test
|
|
198
|
-
PORT=3001
|
|
199
|
-
LOG_LEVEL=silent
|
|
200
|
-
|
|
201
|
-
# Test database
|
|
202
|
-
TEST_DATABASE_URL=sqlite::memory:
|
|
203
|
-
MOCK_EXTERNAL_APIS=true
|
|
204
|
-
|
|
205
|
-
# Frontend test
|
|
206
|
-
VITE_API_URL=http://localhost:3001
|
|
207
|
-
```
|
|
208
|
-
|
|
209
|
-
### **🚀 Production**
|
|
210
|
-
```bash
|
|
211
|
-
# .env.production
|
|
212
|
-
NODE_ENV=production
|
|
213
|
-
LOG_LEVEL=info
|
|
214
|
-
OPTIMIZE_BUNDLE=true
|
|
215
|
-
|
|
216
|
-
# Security - use real environment vars
|
|
217
|
-
JWT_SECRET=${JWT_SECRET}
|
|
218
|
-
API_KEY=${API_KEY}
|
|
219
|
-
DATABASE_URL=${DATABASE_URL}
|
|
220
|
-
```
|
|
221
|
-
|
|
222
|
-
## 📊 **Sistema Dinâmico**
|
|
223
|
-
|
|
224
|
-
### **🔄 Runtime Configuration**
|
|
225
|
-
```typescript
|
|
226
|
-
// core/config/env-dynamic.ts
|
|
227
|
-
export class DynamicEnvConfig {
|
|
228
|
-
static setEnvironment(env: 'development' | 'production' | 'test') {
|
|
229
|
-
process.env.NODE_ENV = env
|
|
230
|
-
// Reconfigure based on environment
|
|
231
|
-
this.loadEnvironmentSpecificConfig()
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
static override(key: string, value: string) {
|
|
235
|
-
process.env[key] = value
|
|
236
|
-
console.log(`Environment override: ${key}=${value}`)
|
|
237
|
-
}
|
|
238
|
-
}
|
|
239
|
-
```
|
|
240
|
-
|
|
241
|
-
### **✅ Precedência em Ação**
|
|
242
|
-
```bash
|
|
243
|
-
# 1. .env file
|
|
244
|
-
PORT=3000
|
|
245
|
-
|
|
246
|
-
# 2. Runtime override
|
|
247
|
-
DynamicEnvConfig.override('PORT', '4000')
|
|
248
|
-
|
|
249
|
-
# 3. Process env (highest priority)
|
|
250
|
-
PORT=5000 bun run dev
|
|
251
|
-
|
|
252
|
-
# Result: PORT=5000 (process env wins)
|
|
253
|
-
```
|
|
254
|
-
|
|
255
|
-
## 🚨 **Security Best Practices**
|
|
256
|
-
|
|
257
|
-
### **🔒 Secrets Management**
|
|
258
|
-
```bash
|
|
259
|
-
# ❌ NUNCA committar secrets
|
|
260
|
-
JWT_SECRET=actual-secret-here # ❌ NO!
|
|
261
|
-
|
|
262
|
-
# ✅ Use placeholders no .env
|
|
263
|
-
JWT_SECRET=${JWT_SECRET} # ✅ YES!
|
|
264
|
-
|
|
265
|
-
# ✅ Set real values via environment
|
|
266
|
-
export JWT_SECRET="actual-secret"
|
|
267
|
-
bun run start
|
|
268
|
-
```
|
|
269
|
-
|
|
270
|
-
### **🛡️ Validation**
|
|
271
|
-
```typescript
|
|
272
|
-
// Validate required vars
|
|
273
|
-
const requiredVars = ['DATABASE_URL', 'JWT_SECRET']
|
|
274
|
-
|
|
275
|
-
for (const varName of requiredVars) {
|
|
276
|
-
if (!process.env[varName]) {
|
|
277
|
-
throw new Error(`Required environment variable missing: ${varName}`)
|
|
278
|
-
}
|
|
279
|
-
}
|
|
280
|
-
```
|
|
281
|
-
|
|
282
|
-
### **🔍 Environment Detection**
|
|
283
|
-
```typescript
|
|
284
|
-
export const isProduction = process.env.NODE_ENV === 'production'
|
|
285
|
-
export const isDevelopment = process.env.NODE_ENV === 'development'
|
|
286
|
-
export const isTest = process.env.NODE_ENV === 'test'
|
|
287
|
-
|
|
288
|
-
// Use guards
|
|
289
|
-
if (isProduction) {
|
|
290
|
-
// Production-only code
|
|
291
|
-
app.use(helmet())
|
|
292
|
-
}
|
|
293
|
-
|
|
294
|
-
if (isDevelopment) {
|
|
295
|
-
// Development-only code
|
|
296
|
-
app.use(cors({ origin: 'http://localhost:5173' }))
|
|
297
|
-
}
|
|
298
|
-
```
|
|
299
|
-
|
|
300
|
-
## 🐳 **Docker Environment**
|
|
301
|
-
|
|
302
|
-
### **📦 Dockerfile ENV**
|
|
303
|
-
```dockerfile
|
|
304
|
-
# Build args
|
|
305
|
-
ARG NODE_ENV=production
|
|
306
|
-
ARG API_URL=http://localhost:3000
|
|
307
|
-
|
|
308
|
-
# Runtime env
|
|
309
|
-
ENV NODE_ENV=${NODE_ENV}
|
|
310
|
-
ENV PORT=3000
|
|
311
|
-
ENV HOST=0.0.0.0
|
|
312
|
-
|
|
313
|
-
# Frontend build vars
|
|
314
|
-
ENV VITE_API_URL=${API_URL}
|
|
315
|
-
ENV VITE_NODE_ENV=${NODE_ENV}
|
|
316
|
-
```
|
|
317
|
-
|
|
318
|
-
### **🚀 Docker Compose**
|
|
319
|
-
```yaml
|
|
320
|
-
# docker-compose.yml
|
|
321
|
-
services:
|
|
322
|
-
app:
|
|
323
|
-
build: .
|
|
324
|
-
environment:
|
|
325
|
-
- NODE_ENV=production
|
|
326
|
-
- PORT=3000
|
|
327
|
-
- DATABASE_URL=${DATABASE_URL}
|
|
328
|
-
- JWT_SECRET=${JWT_SECRET}
|
|
329
|
-
env_file:
|
|
330
|
-
- .env.production
|
|
331
|
-
```
|
|
332
|
-
|
|
333
|
-
## 📋 **Troubleshooting**
|
|
334
|
-
|
|
335
|
-
### **🔍 Debug Environment**
|
|
336
|
-
```typescript
|
|
337
|
-
// Debug current environment
|
|
338
|
-
console.log('Environment Debug:', {
|
|
339
|
-
NODE_ENV: process.env.NODE_ENV,
|
|
340
|
-
PORT: process.env.PORT,
|
|
341
|
-
all_env: Object.keys(process.env).filter(k => k.startsWith('VITE_'))
|
|
342
|
-
})
|
|
343
|
-
```
|
|
344
|
-
|
|
345
|
-
### **⚠️ Problemas Comuns**
|
|
346
|
-
|
|
347
|
-
#### **1. Frontend Vars Não Carregam**
|
|
348
|
-
```bash
|
|
349
|
-
# ❌ Problema: Var sem VITE_ prefix
|
|
350
|
-
API_URL=http://localhost:3000 # Não funciona no frontend
|
|
351
|
-
|
|
352
|
-
# ✅ Solução: Usar VITE_ prefix
|
|
353
|
-
VITE_API_URL=http://localhost:3000 # Funciona!
|
|
354
|
-
```
|
|
355
|
-
|
|
356
|
-
#### **2. Env File Não Carregado**
|
|
357
|
-
```bash
|
|
358
|
-
# Verificar se .env existe no root
|
|
359
|
-
ls -la .env
|
|
360
|
-
|
|
361
|
-
# Verificar conteúdo
|
|
362
|
-
cat .env | grep -v '^#'
|
|
363
|
-
|
|
364
|
-
# Forçar reload
|
|
365
|
-
rm .env && cp .env.example .env
|
|
366
|
-
```
|
|
367
|
-
|
|
368
|
-
#### **3. Docker Env Não Funciona**
|
|
369
|
-
```dockerfile
|
|
370
|
-
# ❌ Problema: ENV muito cedo
|
|
371
|
-
ENV VITE_API_URL=http://localhost:3000
|
|
372
|
-
COPY . .
|
|
373
|
-
RUN bun run build # Vite já buildou com localhost
|
|
374
|
-
|
|
375
|
-
# ✅ Solução: ENV antes do build
|
|
376
|
-
ARG API_URL=http://localhost:3000
|
|
377
|
-
ENV VITE_API_URL=${API_URL}
|
|
378
|
-
COPY . .
|
|
379
|
-
RUN bun run build # Vite builda com ARG correto
|
|
380
|
-
```
|
|
381
|
-
|
|
382
|
-
---
|
|
383
|
-
|
|
384
|
-
**🎯 Sistema de environment variables bem configurado é fundamental para deployment seguro e flexível do FluxStack!**
|