@idealyst/cli 1.0.33 → 1.0.35
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/dist/templates/api/README.md +207 -0
- package/dist/templates/api/__tests__/api.test.ts +26 -0
- package/dist/templates/api/env.example +12 -0
- package/dist/templates/api/jest.config.js +23 -0
- package/dist/templates/api/jest.setup.js +9 -0
- package/dist/templates/api/package.json +62 -0
- package/dist/templates/api/prisma/schema.prisma +21 -0
- package/dist/templates/api/src/context.ts +23 -0
- package/dist/templates/api/src/controllers/UserController.ts +102 -0
- package/dist/templates/api/src/index.ts +14 -0
- package/dist/templates/api/src/lib/controller.ts +90 -0
- package/dist/templates/api/src/lib/middleware.ts +170 -0
- package/dist/templates/api/src/middleware/auth.ts +75 -0
- package/dist/templates/api/src/middleware/common.ts +103 -0
- package/dist/templates/api/src/router/index.ts +130 -0
- package/dist/templates/api/src/server.ts +50 -0
- package/dist/templates/api/src/trpc.ts +28 -0
- package/dist/templates/api/tsconfig.json +44 -0
- package/dist/templates/native/.yarnrc.yml +19 -0
- package/dist/templates/native/App.tsx +23 -0
- package/dist/templates/native/README.md +86 -0
- package/dist/templates/native/__tests__/App.test.tsx +156 -0
- package/dist/templates/native/__tests__/components.test.tsx +300 -0
- package/dist/templates/native/app.json +5 -0
- package/dist/templates/native/babel.config.js +10 -0
- package/dist/templates/native/index.js +6 -0
- package/dist/templates/native/jest.config.js +21 -0
- package/dist/templates/native/jest.setup.js +12 -0
- package/dist/templates/native/metro.config.js +27 -0
- package/dist/templates/native/package.json +44 -0
- package/dist/templates/native/src/App-with-trpc.tsx +59 -0
- package/dist/templates/native/src/utils/trpc.ts +127 -0
- package/dist/templates/native/tsconfig.json +30 -0
- package/dist/templates/shared/README.md +109 -0
- package/dist/templates/shared/__tests__/shared.test.ts +39 -0
- package/dist/templates/shared/jest.config.js +22 -0
- package/dist/templates/shared/package.json +50 -0
- package/dist/templates/shared/rollup.config.js +43 -0
- package/dist/templates/shared/src/index.ts +1 -0
- package/dist/templates/shared/tsconfig.json +25 -0
- package/dist/templates/web/README.md +90 -0
- package/dist/templates/web/__tests__/App.test.tsx +342 -0
- package/dist/templates/web/__tests__/components.test.tsx +564 -0
- package/dist/templates/web/index.html +13 -0
- package/dist/templates/web/jest.config.js +27 -0
- package/dist/templates/web/jest.setup.js +24 -0
- package/dist/templates/web/package.json +66 -0
- package/dist/templates/web/src/App-with-trpc.tsx +67 -0
- package/dist/templates/web/src/App.tsx +15 -0
- package/dist/templates/web/src/main.tsx +25 -0
- package/dist/templates/web/src/utils/trpc.ts +93 -0
- package/dist/templates/web/tsconfig.json +27 -0
- package/dist/templates/web/vite.config.ts +69 -0
- package/dist/templates/workspace/.devcontainer/devcontainer.json +140 -0
- package/dist/templates/workspace/.devcontainer/docker-compose.yml +74 -0
- package/dist/templates/workspace/.dockerignore +151 -0
- package/dist/templates/workspace/.env.example +36 -0
- package/dist/templates/workspace/.env.production +56 -0
- package/dist/templates/workspace/.yarnrc.yml +26 -0
- package/dist/templates/workspace/DOCKER.md +0 -0
- package/dist/templates/workspace/Dockerfile +93 -0
- package/dist/templates/workspace/README.md +179 -0
- package/dist/templates/workspace/docker/nginx/prod.conf +238 -0
- package/dist/templates/workspace/docker/nginx.conf +131 -0
- package/dist/templates/workspace/docker/postgres/init.sql +41 -0
- package/dist/templates/workspace/docker/prometheus/prometheus.yml +52 -0
- package/dist/templates/workspace/docker-compose.prod.yml +146 -0
- package/dist/templates/workspace/docker-compose.yml +144 -0
- package/dist/templates/workspace/jest.config.js +20 -0
- package/dist/templates/workspace/package.json +35 -0
- package/dist/templates/workspace/scripts/docker/db-backup.sh +230 -0
- package/dist/templates/workspace/scripts/docker/deploy.sh +212 -0
- package/dist/templates/workspace/scripts/docker-build.sh +151 -0
- package/dist/templates/workspace/scripts/test-runner.js +120 -0
- package/dist/templates/workspace/setup.sh +205 -0
- package/package.json +3 -2
- package/templates/workspace/.devcontainer/Dockerfile +22 -0
- package/templates/workspace/.devcontainer/devcontainer.json +0 -140
- package/templates/workspace/.devcontainer/docker-compose.yml +13 -26
- package/templates/workspace/.devcontainer/setup.sh +64 -0
- package/templates/workspace/Dockerfile +24 -6
- /package/{templates → dist/templates}/workspace/.devcontainer/post-create.sh +0 -0
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
# Production Environment Variables
|
|
2
|
+
# Copy this file to .env for production deployment
|
|
3
|
+
|
|
4
|
+
# Project Configuration
|
|
5
|
+
PROJECT_NAME={{packageName}}
|
|
6
|
+
NODE_ENV=production
|
|
7
|
+
|
|
8
|
+
# Database Configuration (use strong passwords!)
|
|
9
|
+
POSTGRES_DB={{packageName}}_production
|
|
10
|
+
POSTGRES_USER={{packageName}}_user
|
|
11
|
+
POSTGRES_PASSWORD=CHANGE_THIS_STRONG_PASSWORD
|
|
12
|
+
POSTGRES_PORT=5432
|
|
13
|
+
|
|
14
|
+
# Redis Configuration
|
|
15
|
+
REDIS_PORT=6379
|
|
16
|
+
|
|
17
|
+
# API Configuration
|
|
18
|
+
API_PORT=3001
|
|
19
|
+
JWT_SECRET=CHANGE_THIS_VERY_STRONG_JWT_SECRET_MINIMUM_32_CHARACTERS
|
|
20
|
+
|
|
21
|
+
# Web Configuration
|
|
22
|
+
WEB_PORT=80
|
|
23
|
+
|
|
24
|
+
# SSL/Domain Configuration
|
|
25
|
+
DOMAIN_NAME=yourdomain.com
|
|
26
|
+
SSL_EMAIL=admin@yourdomain.com
|
|
27
|
+
|
|
28
|
+
# Monitoring
|
|
29
|
+
GRAFANA_PASSWORD=CHANGE_THIS_STRONG_PASSWORD
|
|
30
|
+
|
|
31
|
+
# Logging
|
|
32
|
+
LOG_LEVEL=warn
|
|
33
|
+
|
|
34
|
+
# Rate Limiting (more restrictive for production)
|
|
35
|
+
RATE_LIMIT_WINDOW_MS=900000
|
|
36
|
+
RATE_LIMIT_MAX_REQUESTS=50
|
|
37
|
+
|
|
38
|
+
# Security Settings
|
|
39
|
+
SESSION_SECRET=CHANGE_THIS_VERY_STRONG_SESSION_SECRET
|
|
40
|
+
ENCRYPTION_KEY=CHANGE_THIS_32_CHARACTER_ENCRYPTION_KEY
|
|
41
|
+
|
|
42
|
+
# External Services (configure as needed)
|
|
43
|
+
# SMTP_HOST=smtp.yourdomain.com
|
|
44
|
+
# SMTP_PORT=587
|
|
45
|
+
# SMTP_USER=noreply@yourdomain.com
|
|
46
|
+
# SMTP_PASS=smtp_password
|
|
47
|
+
|
|
48
|
+
# AWS/Cloud Storage (if using)
|
|
49
|
+
# AWS_ACCESS_KEY_ID=your_access_key
|
|
50
|
+
# AWS_SECRET_ACCESS_KEY=your_secret_key
|
|
51
|
+
# AWS_REGION=us-east-1
|
|
52
|
+
# S3_BUCKET=your-bucket-name
|
|
53
|
+
|
|
54
|
+
# Analytics/Monitoring
|
|
55
|
+
# SENTRY_DSN=your_sentry_dsn
|
|
56
|
+
# GOOGLE_ANALYTICS_ID=your_ga_id
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
nodeLinker: "node-modules"
|
|
2
|
+
|
|
3
|
+
# Enable transparent workspaces for better workspace dependency resolution
|
|
4
|
+
enableTransparentWorkspaces: true
|
|
5
|
+
|
|
6
|
+
# Enable network for package downloads
|
|
7
|
+
enableNetwork: true
|
|
8
|
+
|
|
9
|
+
# Timeout for HTTP requests (in milliseconds)
|
|
10
|
+
httpTimeout: 60000
|
|
11
|
+
|
|
12
|
+
# Number of retry attempts for HTTP requests
|
|
13
|
+
httpRetry: 3
|
|
14
|
+
|
|
15
|
+
# Registry configuration
|
|
16
|
+
npmRegistryServer: "https://registry.yarnpkg.com"
|
|
17
|
+
|
|
18
|
+
# Enable progress bars
|
|
19
|
+
enableProgressBars: true
|
|
20
|
+
|
|
21
|
+
# Enable colors in output
|
|
22
|
+
enableColors: true
|
|
23
|
+
|
|
24
|
+
# Prevent hoisting to avoid React Native issues
|
|
25
|
+
# This ensures React Native dependencies stay in their local node_modules
|
|
26
|
+
nmHoistingLimits: workspaces
|
|
File without changes
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
# Multi-stage Dockerfile for Idealyst Workspace
|
|
2
|
+
# Supports web apps, API services, and can be used for staging/production
|
|
3
|
+
|
|
4
|
+
# Base stage with Node.js and build tools
|
|
5
|
+
FROM node:20-bullseye-slim AS base
|
|
6
|
+
RUN apt-get update && apt-get install -y \
|
|
7
|
+
libc6-dev \
|
|
8
|
+
git \
|
|
9
|
+
&& rm -rf /var/lib/apt/lists/*
|
|
10
|
+
WORKDIR /app
|
|
11
|
+
|
|
12
|
+
# Enable corepack for yarn
|
|
13
|
+
RUN corepack enable
|
|
14
|
+
|
|
15
|
+
# Dependencies stage - install all dependencies
|
|
16
|
+
FROM base AS deps
|
|
17
|
+
COPY package.json yarn.lock .yarnrc.yml ./
|
|
18
|
+
COPY .yarn .yarn
|
|
19
|
+
|
|
20
|
+
# Create packages directory structure and copy package.json files
|
|
21
|
+
RUN mkdir -p packages/api packages/app packages/components packages/web
|
|
22
|
+
COPY packages/api/package.json ./packages/api/
|
|
23
|
+
COPY packages/app/package.json ./packages/app/
|
|
24
|
+
COPY packages/components/package.json ./packages/components/
|
|
25
|
+
COPY packages/web/package.json ./packages/web/
|
|
26
|
+
|
|
27
|
+
RUN yarn install
|
|
28
|
+
|
|
29
|
+
# Build stage - build all packages
|
|
30
|
+
FROM base AS builder
|
|
31
|
+
COPY --from=deps /app/node_modules ./node_modules
|
|
32
|
+
COPY . .
|
|
33
|
+
|
|
34
|
+
# Build all packages
|
|
35
|
+
RUN yarn build:all
|
|
36
|
+
|
|
37
|
+
# Production API stage
|
|
38
|
+
FROM base AS api-runner
|
|
39
|
+
RUN addgroup --system --gid 1001 nodejs
|
|
40
|
+
RUN adduser --system --uid 1001 apiuser
|
|
41
|
+
|
|
42
|
+
# Copy built API and dependencies
|
|
43
|
+
COPY --from=builder /app/packages/*/dist ./packages/
|
|
44
|
+
COPY --from=builder /app/node_modules ./node_modules
|
|
45
|
+
COPY --from=builder /app/package.json ./
|
|
46
|
+
|
|
47
|
+
USER apiuser
|
|
48
|
+
EXPOSE 3001
|
|
49
|
+
ENV NODE_ENV=production
|
|
50
|
+
ENV PORT=3001
|
|
51
|
+
|
|
52
|
+
# Health check for API
|
|
53
|
+
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
|
|
54
|
+
CMD node -e "require('http').get('http://localhost:3001/health', (res) => { process.exit(res.statusCode === 200 ? 0 : 1) })"
|
|
55
|
+
|
|
56
|
+
CMD ["node", "packages/api/dist/server.js"]
|
|
57
|
+
|
|
58
|
+
# Production Web stage
|
|
59
|
+
FROM nginx:alpine AS web-runner
|
|
60
|
+
COPY --from=builder /app/packages/web/dist /usr/share/nginx/html
|
|
61
|
+
COPY docker/nginx.conf /etc/nginx/nginx.conf
|
|
62
|
+
|
|
63
|
+
EXPOSE 80
|
|
64
|
+
CMD ["nginx", "-g", "daemon off;"]
|
|
65
|
+
|
|
66
|
+
# Development stage - for use with dev containers
|
|
67
|
+
FROM base AS dev
|
|
68
|
+
|
|
69
|
+
# Copy package files
|
|
70
|
+
COPY package.json yarn.lock .yarnrc.yml ./
|
|
71
|
+
COPY .yarn .yarn
|
|
72
|
+
|
|
73
|
+
# Create packages directory structure and copy package.json files
|
|
74
|
+
RUN mkdir -p packages/api packages/app packages/components packages/web
|
|
75
|
+
COPY packages/api/package.json ./packages/api/
|
|
76
|
+
COPY packages/app/package.json ./packages/app/
|
|
77
|
+
COPY packages/components/package.json ./packages/components/
|
|
78
|
+
COPY packages/web/package.json ./packages/web/
|
|
79
|
+
|
|
80
|
+
# Install dependencies including dev dependencies
|
|
81
|
+
RUN yarn install
|
|
82
|
+
|
|
83
|
+
EXPOSE 3000 3001 5173 8080 19006
|
|
84
|
+
|
|
85
|
+
CMD ["tail", "-f", "/dev/null"]
|
|
86
|
+
|
|
87
|
+
# Test runner stage
|
|
88
|
+
FROM base AS test-runner
|
|
89
|
+
COPY --from=deps /app/node_modules ./node_modules
|
|
90
|
+
COPY . .
|
|
91
|
+
|
|
92
|
+
# Run tests
|
|
93
|
+
CMD ["yarn", "test:ci"]
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
# {{projectName}}
|
|
2
|
+
|
|
3
|
+
{{description}}
|
|
4
|
+
|
|
5
|
+
## Getting Started
|
|
6
|
+
|
|
7
|
+
This workspace contains your Idealyst Framework packages and applications.
|
|
8
|
+
|
|
9
|
+
### Structure
|
|
10
|
+
|
|
11
|
+
```
|
|
12
|
+
{{projectName}}/
|
|
13
|
+
├── packages/ # Shared packages
|
|
14
|
+
│ ├── theme/ # Theme configuration
|
|
15
|
+
│ ├── components/ # UI components
|
|
16
|
+
│ └── utils/ # Shared utilities
|
|
17
|
+
├── mobile-app/ # React Native app (generated)
|
|
18
|
+
├── web-app/ # React web app (generated)
|
|
19
|
+
└── shared-lib/ # Shared library (generated)
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
## Testing
|
|
23
|
+
|
|
24
|
+
This workspace is pre-configured with Jest testing framework across all packages. Each package includes sample tests and Jest configuration.
|
|
25
|
+
|
|
26
|
+
### Quick Start
|
|
27
|
+
|
|
28
|
+
```bash
|
|
29
|
+
# Run all tests across all packages
|
|
30
|
+
yarn test
|
|
31
|
+
|
|
32
|
+
# Run tests in watch mode
|
|
33
|
+
yarn test:watch
|
|
34
|
+
|
|
35
|
+
# Run tests with coverage reports
|
|
36
|
+
yarn test:coverage
|
|
37
|
+
|
|
38
|
+
# Run tests in CI mode (for automated builds)
|
|
39
|
+
yarn test:ci
|
|
40
|
+
|
|
41
|
+
# Run tests for a specific package
|
|
42
|
+
node scripts/test-runner.js test:package <package-name>
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
### Test Structure
|
|
46
|
+
|
|
47
|
+
Each package contains:
|
|
48
|
+
- `jest.config.js` - Jest configuration tailored to the project type
|
|
49
|
+
- `__tests__/` - Directory for test files with comprehensive examples
|
|
50
|
+
- Sample tests demonstrating testing patterns specific to each template
|
|
51
|
+
|
|
52
|
+
### Package-Specific Testing
|
|
53
|
+
|
|
54
|
+
- **API packages**: Node.js environment, async/database testing patterns
|
|
55
|
+
- **Web packages**: React Testing Library, DOM testing, user interactions
|
|
56
|
+
- **Native packages**: React Native Testing Library, component rendering
|
|
57
|
+
- **Shared packages**: TypeScript utility testing patterns
|
|
58
|
+
|
|
59
|
+
### Adding Tests
|
|
60
|
+
|
|
61
|
+
1. Create test files in the `__tests__` directory or alongside your source files with `.test.ts` or `.spec.ts` extension
|
|
62
|
+
2. Tests are automatically discovered and run by Jest
|
|
63
|
+
3. Each template includes comprehensive sample tests as starting points
|
|
64
|
+
4. See the Component Testing Guide for detailed patterns and best practices
|
|
65
|
+
|
|
66
|
+
### Development
|
|
67
|
+
|
|
68
|
+
Install dependencies:
|
|
69
|
+
```bash
|
|
70
|
+
yarn install
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
Build all packages:
|
|
74
|
+
```bash
|
|
75
|
+
yarn build:all
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
Test all packages:
|
|
79
|
+
```bash
|
|
80
|
+
yarn test:all
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
### Adding Applications
|
|
84
|
+
|
|
85
|
+
Generate a new React Native app:
|
|
86
|
+
```bash
|
|
87
|
+
idealyst create mobile-app --type native
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
Generate a new React web app:
|
|
91
|
+
```bash
|
|
92
|
+
idealyst create web-app --type web
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
Generate a new shared library:
|
|
96
|
+
```bash
|
|
97
|
+
idealyst create shared-lib --type shared
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
**Note:** The CLI will automatically add new projects to the workspace configuration when run from the workspace root.
|
|
101
|
+
|
|
102
|
+
### Publishing
|
|
103
|
+
|
|
104
|
+
Publish all packages:
|
|
105
|
+
```bash
|
|
106
|
+
yarn publish:all
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
### Version Management
|
|
110
|
+
|
|
111
|
+
Update patch version for all packages:
|
|
112
|
+
```bash
|
|
113
|
+
yarn version:patch
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
Update minor version for all packages:
|
|
117
|
+
```bash
|
|
118
|
+
yarn version:minor
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
Update major version for all packages:
|
|
122
|
+
```bash
|
|
123
|
+
yarn version:major
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
## Docker & Containerization
|
|
127
|
+
|
|
128
|
+
This workspace includes comprehensive Docker support for development, staging, and production environments.
|
|
129
|
+
|
|
130
|
+
### Quick Start with Docker
|
|
131
|
+
|
|
132
|
+
```bash
|
|
133
|
+
# Use the Docker build helper (recommended)
|
|
134
|
+
./scripts/docker-build.sh dev
|
|
135
|
+
|
|
136
|
+
# Or manually:
|
|
137
|
+
# Development environment
|
|
138
|
+
cp .env.example .env
|
|
139
|
+
./scripts/docker/deploy.sh development
|
|
140
|
+
|
|
141
|
+
# Production deployment
|
|
142
|
+
cp .env.production .env
|
|
143
|
+
# Edit .env with your settings
|
|
144
|
+
./scripts/docker/deploy.sh production
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
**Docker Build Helper**: The `./scripts/docker-build.sh` script automatically handles common issues like missing yarn.lock files and environment configuration.
|
|
148
|
+
|
|
149
|
+
### VS Code Dev Container
|
|
150
|
+
|
|
151
|
+
Open this workspace in VS Code and select "Reopen in Container" for a fully configured development environment with:
|
|
152
|
+
- Node.js, TypeScript, and all development tools pre-installed
|
|
153
|
+
- PostgreSQL and Redis databases ready to use
|
|
154
|
+
- Automatic port forwarding and extension installation
|
|
155
|
+
- Hot reload and debugging support
|
|
156
|
+
|
|
157
|
+
### Services Available
|
|
158
|
+
|
|
159
|
+
- **Web App**: React application with hot reload
|
|
160
|
+
- **API Server**: Backend with database connections
|
|
161
|
+
- **PostgreSQL**: Database with initialization scripts
|
|
162
|
+
- **Redis**: Caching and session storage
|
|
163
|
+
- **Nginx**: Reverse proxy and load balancer (production)
|
|
164
|
+
|
|
165
|
+
### Management Scripts
|
|
166
|
+
|
|
167
|
+
```bash
|
|
168
|
+
# Deployment
|
|
169
|
+
./scripts/docker/deploy.sh [development|production|staging]
|
|
170
|
+
|
|
171
|
+
# Database management
|
|
172
|
+
./scripts/docker/db-backup.sh [backup|restore|list|clean]
|
|
173
|
+
|
|
174
|
+
# View status
|
|
175
|
+
./scripts/docker/deploy.sh status
|
|
176
|
+
|
|
177
|
+
# View logs
|
|
178
|
+
./scripts/docker/deploy.sh logs
|
|
179
|
+
```
|
|
@@ -0,0 +1,238 @@
|
|
|
1
|
+
events {
|
|
2
|
+
worker_connections 2048;
|
|
3
|
+
use epoll;
|
|
4
|
+
multi_accept on;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
http {
|
|
8
|
+
include /etc/nginx/mime.types;
|
|
9
|
+
default_type application/octet-stream;
|
|
10
|
+
|
|
11
|
+
# Logging
|
|
12
|
+
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
|
|
13
|
+
'$status $body_bytes_sent "$http_referer" '
|
|
14
|
+
'"$http_user_agent" "$http_x_forwarded_for" '
|
|
15
|
+
'$request_time $upstream_response_time';
|
|
16
|
+
|
|
17
|
+
access_log /var/log/nginx/access.log main;
|
|
18
|
+
error_log /var/log/nginx/error.log warn;
|
|
19
|
+
|
|
20
|
+
# Performance settings
|
|
21
|
+
sendfile on;
|
|
22
|
+
tcp_nopush on;
|
|
23
|
+
tcp_nodelay on;
|
|
24
|
+
keepalive_timeout 65;
|
|
25
|
+
keepalive_requests 100;
|
|
26
|
+
types_hash_max_size 2048;
|
|
27
|
+
server_tokens off;
|
|
28
|
+
client_max_body_size 50M;
|
|
29
|
+
client_body_buffer_size 128k;
|
|
30
|
+
client_header_buffer_size 3m;
|
|
31
|
+
large_client_header_buffers 4 256k;
|
|
32
|
+
|
|
33
|
+
# SSL Configuration
|
|
34
|
+
ssl_protocols TLSv1.2 TLSv1.3;
|
|
35
|
+
ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-RSA-AES128-SHA256:ECDHE-RSA-AES256-SHA384;
|
|
36
|
+
ssl_prefer_server_ciphers off;
|
|
37
|
+
ssl_session_cache shared:SSL:10m;
|
|
38
|
+
ssl_session_timeout 10m;
|
|
39
|
+
|
|
40
|
+
# Gzip compression
|
|
41
|
+
gzip on;
|
|
42
|
+
gzip_vary on;
|
|
43
|
+
gzip_min_length 1024;
|
|
44
|
+
gzip_comp_level 6;
|
|
45
|
+
gzip_proxied any;
|
|
46
|
+
gzip_types
|
|
47
|
+
application/atom+xml
|
|
48
|
+
application/geo+json
|
|
49
|
+
application/javascript
|
|
50
|
+
application/x-javascript
|
|
51
|
+
application/json
|
|
52
|
+
application/ld+json
|
|
53
|
+
application/manifest+json
|
|
54
|
+
application/rdf+xml
|
|
55
|
+
application/rss+xml
|
|
56
|
+
application/xhtml+xml
|
|
57
|
+
application/xml
|
|
58
|
+
font/eot
|
|
59
|
+
font/otf
|
|
60
|
+
font/ttf
|
|
61
|
+
image/svg+xml
|
|
62
|
+
text/css
|
|
63
|
+
text/javascript
|
|
64
|
+
text/plain
|
|
65
|
+
text/xml;
|
|
66
|
+
|
|
67
|
+
# Rate limiting zones
|
|
68
|
+
limit_req_zone $binary_remote_addr zone=api:10m rate=10r/s;
|
|
69
|
+
limit_req_zone $binary_remote_addr zone=web:10m rate=50r/s;
|
|
70
|
+
limit_req_zone $binary_remote_addr zone=login:10m rate=5r/m;
|
|
71
|
+
|
|
72
|
+
# Connection limiting
|
|
73
|
+
limit_conn_zone $binary_remote_addr zone=conn_limit_per_ip:10m;
|
|
74
|
+
limit_conn conn_limit_per_ip 20;
|
|
75
|
+
|
|
76
|
+
# Upstream servers with load balancing
|
|
77
|
+
upstream api_backend {
|
|
78
|
+
least_conn;
|
|
79
|
+
server {{PROJECT_NAME}}-api-1:3001 max_fails=3 fail_timeout=30s weight=1;
|
|
80
|
+
server {{PROJECT_NAME}}-api-2:3001 max_fails=3 fail_timeout=30s weight=1;
|
|
81
|
+
keepalive 32;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
upstream web_backend {
|
|
85
|
+
least_conn;
|
|
86
|
+
server {{PROJECT_NAME}}-web-1:80 max_fails=3 fail_timeout=30s weight=1;
|
|
87
|
+
server {{PROJECT_NAME}}-web-2:80 max_fails=3 fail_timeout=30s weight=1;
|
|
88
|
+
keepalive 32;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
# Cache zones
|
|
92
|
+
proxy_cache_path /var/cache/nginx levels=1:2 keys_zone=api_cache:10m max_size=1g inactive=60m use_temp_path=off;
|
|
93
|
+
proxy_cache_path /var/cache/nginx/static levels=1:2 keys_zone=static_cache:10m max_size=1g inactive=24h use_temp_path=off;
|
|
94
|
+
|
|
95
|
+
# Redirect HTTP to HTTPS
|
|
96
|
+
server {
|
|
97
|
+
listen 80;
|
|
98
|
+
server_name {{DOMAIN_NAME}};
|
|
99
|
+
return 301 https://$server_name$request_uri;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
# Main HTTPS server
|
|
103
|
+
server {
|
|
104
|
+
listen 443 ssl http2;
|
|
105
|
+
server_name {{DOMAIN_NAME}};
|
|
106
|
+
|
|
107
|
+
# SSL certificates
|
|
108
|
+
ssl_certificate /etc/nginx/ssl/cert.pem;
|
|
109
|
+
ssl_certificate_key /etc/nginx/ssl/key.pem;
|
|
110
|
+
|
|
111
|
+
# Security headers
|
|
112
|
+
add_header Strict-Transport-Security "max-age=31536000; includeSubDomains; preload" always;
|
|
113
|
+
add_header X-Frame-Options "SAMEORIGIN" always;
|
|
114
|
+
add_header X-Content-Type-Options "nosniff" always;
|
|
115
|
+
add_header X-XSS-Protection "1; mode=block" always;
|
|
116
|
+
add_header Referrer-Policy "strict-origin-when-cross-origin" always;
|
|
117
|
+
add_header Content-Security-Policy "default-src 'self'; script-src 'self' 'unsafe-inline' 'unsafe-eval'; style-src 'self' 'unsafe-inline'; img-src 'self' data: https:; font-src 'self' data:; connect-src 'self' wss:; frame-ancestors 'self';" always;
|
|
118
|
+
|
|
119
|
+
# API routes
|
|
120
|
+
location /api/ {
|
|
121
|
+
limit_req zone=api burst=20 nodelay;
|
|
122
|
+
|
|
123
|
+
# Caching for GET requests
|
|
124
|
+
proxy_cache api_cache;
|
|
125
|
+
proxy_cache_valid 200 302 10m;
|
|
126
|
+
proxy_cache_valid 404 1m;
|
|
127
|
+
proxy_cache_use_stale error timeout updating http_500 http_502 http_503 http_504;
|
|
128
|
+
proxy_cache_lock on;
|
|
129
|
+
proxy_cache_bypass $http_cache_control;
|
|
130
|
+
|
|
131
|
+
proxy_pass http://api_backend/;
|
|
132
|
+
proxy_http_version 1.1;
|
|
133
|
+
proxy_set_header Upgrade $http_upgrade;
|
|
134
|
+
proxy_set_header Connection 'upgrade';
|
|
135
|
+
proxy_set_header Host $host;
|
|
136
|
+
proxy_set_header X-Real-IP $remote_addr;
|
|
137
|
+
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
|
138
|
+
proxy_set_header X-Forwarded-Proto $scheme;
|
|
139
|
+
proxy_cache_bypass $http_upgrade;
|
|
140
|
+
proxy_connect_timeout 30s;
|
|
141
|
+
proxy_send_timeout 30s;
|
|
142
|
+
proxy_read_timeout 30s;
|
|
143
|
+
proxy_buffering on;
|
|
144
|
+
proxy_buffer_size 4k;
|
|
145
|
+
proxy_buffers 8 4k;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
# Health checks
|
|
149
|
+
location /api/health {
|
|
150
|
+
proxy_pass http://api_backend/health;
|
|
151
|
+
access_log off;
|
|
152
|
+
proxy_cache off;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
# Authentication endpoints (stricter rate limiting)
|
|
156
|
+
location ~ ^/api/(auth|login|register|password) {
|
|
157
|
+
limit_req zone=login burst=5 nodelay;
|
|
158
|
+
|
|
159
|
+
proxy_pass http://api_backend;
|
|
160
|
+
proxy_set_header Host $host;
|
|
161
|
+
proxy_set_header X-Real-IP $remote_addr;
|
|
162
|
+
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
|
163
|
+
proxy_set_header X-Forwarded-Proto $scheme;
|
|
164
|
+
proxy_cache off;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
# Static assets with aggressive caching
|
|
168
|
+
location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg|webp|woff|woff2|ttf|eot|pdf)$ {
|
|
169
|
+
limit_req zone=web burst=100 nodelay;
|
|
170
|
+
|
|
171
|
+
proxy_cache static_cache;
|
|
172
|
+
proxy_cache_valid 200 1y;
|
|
173
|
+
proxy_cache_use_stale error timeout updating http_500 http_502 http_503 http_504;
|
|
174
|
+
|
|
175
|
+
proxy_pass http://web_backend;
|
|
176
|
+
expires 1y;
|
|
177
|
+
add_header Cache-Control "public, immutable";
|
|
178
|
+
add_header X-Content-Type-Options "nosniff";
|
|
179
|
+
|
|
180
|
+
# CORS headers for fonts and assets
|
|
181
|
+
add_header Access-Control-Allow-Origin "*";
|
|
182
|
+
add_header Access-Control-Allow-Methods "GET, OPTIONS";
|
|
183
|
+
add_header Access-Control-Allow-Headers "DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range";
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
# Web application with caching
|
|
187
|
+
location / {
|
|
188
|
+
limit_req zone=web burst=50 nodelay;
|
|
189
|
+
|
|
190
|
+
# Short cache for HTML files
|
|
191
|
+
proxy_cache static_cache;
|
|
192
|
+
proxy_cache_valid 200 10m;
|
|
193
|
+
proxy_cache_use_stale error timeout updating http_500 http_502 http_503 http_504;
|
|
194
|
+
proxy_cache_bypass $http_cache_control;
|
|
195
|
+
|
|
196
|
+
proxy_pass http://web_backend;
|
|
197
|
+
proxy_http_version 1.1;
|
|
198
|
+
proxy_set_header Upgrade $http_upgrade;
|
|
199
|
+
proxy_set_header Connection 'upgrade';
|
|
200
|
+
proxy_set_header Host $host;
|
|
201
|
+
proxy_set_header X-Real-IP $remote_addr;
|
|
202
|
+
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
|
203
|
+
proxy_set_header X-Forwarded-Proto $scheme;
|
|
204
|
+
proxy_cache_bypass $http_upgrade;
|
|
205
|
+
|
|
206
|
+
# Handle client-side routing
|
|
207
|
+
try_files $uri $uri/ @fallback;
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
# Fallback for client-side routing
|
|
211
|
+
location @fallback {
|
|
212
|
+
proxy_pass http://web_backend;
|
|
213
|
+
proxy_set_header Host $host;
|
|
214
|
+
proxy_set_header X-Real-IP $remote_addr;
|
|
215
|
+
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
|
216
|
+
proxy_set_header X-Forwarded-Proto $scheme;
|
|
217
|
+
proxy_cache off;
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
# Monitoring endpoint
|
|
221
|
+
location /nginx_status {
|
|
222
|
+
stub_status on;
|
|
223
|
+
access_log off;
|
|
224
|
+
allow 127.0.0.1;
|
|
225
|
+
allow 10.0.0.0/8;
|
|
226
|
+
allow 172.16.0.0/12;
|
|
227
|
+
allow 192.168.0.0/16;
|
|
228
|
+
deny all;
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
# Health check endpoint
|
|
232
|
+
location /health {
|
|
233
|
+
access_log off;
|
|
234
|
+
return 200 "healthy\n";
|
|
235
|
+
add_header Content-Type text/plain;
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
}
|