rapidkit 0.11.3 → 0.12.1
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/README.md +99 -411
- package/dist/index.js +507 -640
- package/dist/package.json +1 -1
- package/package.json +1 -1
- package/templates/generator.js +175 -0
- package/templates/kits/fastapi-standard/.rapidkit/__init__.py.j2 +1 -0
- package/templates/kits/fastapi-standard/.rapidkit/activate.j2 +24 -0
- package/templates/kits/fastapi-standard/.rapidkit/cli.py.j2 +6 -4
- package/templates/kits/fastapi-standard/.rapidkit/project.json.j2 +3 -2
- package/templates/kits/fastapi-standard/.rapidkit/rapidkit.j2 +31 -0
- package/templates/kits/fastapi-standard/Makefile.j2 +41 -0
- package/templates/kits/fastapi-standard/pyproject.toml.j2 +1 -0
- package/templates/kits/fastapi-standard/rapidkit.j2 +50 -0
- package/templates/kits/nestjs-standard/.env.example.j2 +16 -0
- package/templates/kits/nestjs-standard/.eslintrc.js.j2 +25 -0
- package/templates/kits/nestjs-standard/.gitignore.j2 +26 -0
- package/templates/kits/nestjs-standard/.node-version.j2 +1 -0
- package/templates/kits/nestjs-standard/.nvmrc.j2 +1 -0
- package/templates/kits/nestjs-standard/.prettierrc.j2 +7 -0
- package/templates/kits/nestjs-standard/.rapidkit/activate.j2 +25 -0
- package/templates/kits/nestjs-standard/.rapidkit/project.json.j2 +7 -0
- package/templates/kits/nestjs-standard/.rapidkit/rapidkit.j2 +227 -0
- package/templates/kits/nestjs-standard/README.md.j2 +97 -0
- package/templates/kits/nestjs-standard/jest.config.ts.j2 +21 -0
- package/templates/kits/nestjs-standard/nest-cli.json.j2 +10 -0
- package/templates/kits/nestjs-standard/package.json.j2 +75 -0
- package/templates/kits/nestjs-standard/rapidkit.j2 +5 -0
- package/templates/kits/nestjs-standard/src/app.controller.ts.j2 +12 -0
- package/templates/kits/nestjs-standard/src/app.module.ts.j2 +23 -0
- package/templates/kits/nestjs-standard/src/app.service.ts.j2 +11 -0
- package/templates/kits/nestjs-standard/src/config/configuration.ts.j2 +9 -0
- package/templates/kits/nestjs-standard/src/config/index.ts.j2 +2 -0
- package/templates/kits/nestjs-standard/src/config/validation.ts.j2 +11 -0
- package/templates/kits/nestjs-standard/src/examples/dto/create-note.dto.ts.j2 +11 -0
- package/templates/kits/nestjs-standard/src/examples/examples.controller.ts.j2 +24 -0
- package/templates/kits/nestjs-standard/src/examples/examples.module.ts.j2 +10 -0
- package/templates/kits/nestjs-standard/src/examples/examples.service.ts.j2 +33 -0
- package/templates/kits/nestjs-standard/src/main.ts.j2 +51 -0
- package/templates/kits/nestjs-standard/src/modules/index.ts.j2 +3 -0
- package/templates/kits/nestjs-standard/test/app.controller.spec.ts.j2 +22 -0
- package/templates/kits/nestjs-standard/test/app.e2e-spec.ts.j2 +48 -0
- package/templates/kits/nestjs-standard/test/examples.controller.spec.ts.j2 +28 -0
- package/templates/kits/nestjs-standard/test/jest-e2e.json.j2 +15 -0
- package/templates/kits/nestjs-standard/tsconfig.build.json.j2 +12 -0
- package/templates/kits/nestjs-standard/tsconfig.json.j2 +26 -0
|
@@ -0,0 +1,227 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# RapidKit CLI wrapper for NestJS projects (npm demo template)
|
|
3
|
+
# This script provides local commands that mirror the full RapidKit engine.
|
|
4
|
+
|
|
5
|
+
set -e
|
|
6
|
+
|
|
7
|
+
PROJECT_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
|
|
8
|
+
cd "$PROJECT_ROOT"
|
|
9
|
+
|
|
10
|
+
print_banner() {
|
|
11
|
+
local emoji="$1"
|
|
12
|
+
local message="$2"
|
|
13
|
+
echo "$emoji $message"
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
check_node() {
|
|
17
|
+
if ! command -v node &> /dev/null; then
|
|
18
|
+
echo "❌ Node.js not found. Please install Node.js first."
|
|
19
|
+
exit 1
|
|
20
|
+
fi
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
check_npm_or_pnpm() {
|
|
24
|
+
if command -v pnpm &> /dev/null; then
|
|
25
|
+
echo "pnpm"
|
|
26
|
+
elif command -v npm &> /dev/null; then
|
|
27
|
+
echo "npm"
|
|
28
|
+
else
|
|
29
|
+
echo "❌ Neither npm nor pnpm found. Please install Node.js first."
|
|
30
|
+
exit 1
|
|
31
|
+
fi
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
cmd_init() {
|
|
35
|
+
print_banner "📦" "Bootstrapping NestJS project (installing dependencies)"
|
|
36
|
+
check_node
|
|
37
|
+
|
|
38
|
+
local pkg_manager=$(check_npm_or_pnpm)
|
|
39
|
+
|
|
40
|
+
if [ "$pkg_manager" = "pnpm" ]; then
|
|
41
|
+
pnpm install
|
|
42
|
+
else
|
|
43
|
+
npm install
|
|
44
|
+
fi
|
|
45
|
+
|
|
46
|
+
echo "✅ Dependencies installed successfully!"
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
cmd_dev() {
|
|
50
|
+
local port="${1:-8000}"
|
|
51
|
+
local host="${2:-0.0.0.0}"
|
|
52
|
+
|
|
53
|
+
print_banner "🚀" "Starting NestJS development server with hot reload..."
|
|
54
|
+
check_node
|
|
55
|
+
|
|
56
|
+
if [ ! -d "node_modules" ]; then
|
|
57
|
+
echo "❌ node_modules not found. Run 'rapidkit init' first."
|
|
58
|
+
exit 1
|
|
59
|
+
fi
|
|
60
|
+
|
|
61
|
+
local pkg_manager=$(check_npm_or_pnpm)
|
|
62
|
+
|
|
63
|
+
if [ "$pkg_manager" = "pnpm" ]; then
|
|
64
|
+
PORT="$port" HOST="$host" pnpm run start:dev
|
|
65
|
+
else
|
|
66
|
+
PORT="$port" HOST="$host" npm run start:dev
|
|
67
|
+
fi
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
cmd_start() {
|
|
71
|
+
local port="${1:-8000}"
|
|
72
|
+
local host="${2:-0.0.0.0}"
|
|
73
|
+
|
|
74
|
+
print_banner "⚡" "Starting NestJS production server..."
|
|
75
|
+
check_node
|
|
76
|
+
|
|
77
|
+
if [ ! -d "node_modules" ]; then
|
|
78
|
+
echo "❌ node_modules not found. Run 'rapidkit init' first."
|
|
79
|
+
exit 1
|
|
80
|
+
fi
|
|
81
|
+
|
|
82
|
+
local pkg_manager=$(check_npm_or_pnpm)
|
|
83
|
+
|
|
84
|
+
if [ "$pkg_manager" = "pnpm" ]; then
|
|
85
|
+
PORT="$port" HOST="$host" pnpm run start:prod
|
|
86
|
+
else
|
|
87
|
+
PORT="$port" HOST="$host" npm run start:prod
|
|
88
|
+
fi
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
cmd_build() {
|
|
92
|
+
print_banner "📦" "Building NestJS project..."
|
|
93
|
+
check_node
|
|
94
|
+
|
|
95
|
+
local pkg_manager=$(check_npm_or_pnpm)
|
|
96
|
+
|
|
97
|
+
if [ "$pkg_manager" = "pnpm" ]; then
|
|
98
|
+
pnpm run build
|
|
99
|
+
else
|
|
100
|
+
npm run build
|
|
101
|
+
fi
|
|
102
|
+
|
|
103
|
+
echo "✅ Build completed!"
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
cmd_test() {
|
|
107
|
+
print_banner "🧪" "Running tests..."
|
|
108
|
+
check_node
|
|
109
|
+
|
|
110
|
+
local pkg_manager=$(check_npm_or_pnpm)
|
|
111
|
+
|
|
112
|
+
if [ "$pkg_manager" = "pnpm" ]; then
|
|
113
|
+
pnpm run test
|
|
114
|
+
else
|
|
115
|
+
npm run test
|
|
116
|
+
fi
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
cmd_lint() {
|
|
120
|
+
print_banner "🔧" "Running ESLint..."
|
|
121
|
+
check_node
|
|
122
|
+
|
|
123
|
+
local pkg_manager=$(check_npm_or_pnpm)
|
|
124
|
+
|
|
125
|
+
if [ "$pkg_manager" = "pnpm" ]; then
|
|
126
|
+
pnpm run lint
|
|
127
|
+
else
|
|
128
|
+
npm run lint
|
|
129
|
+
fi
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
cmd_format() {
|
|
133
|
+
print_banner "✨" "Formatting code with Prettier..."
|
|
134
|
+
check_node
|
|
135
|
+
|
|
136
|
+
local pkg_manager=$(check_npm_or_pnpm)
|
|
137
|
+
|
|
138
|
+
if [ "$pkg_manager" = "pnpm" ]; then
|
|
139
|
+
pnpm run format
|
|
140
|
+
else
|
|
141
|
+
npm run format
|
|
142
|
+
fi
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
cmd_help() {
|
|
146
|
+
print_banner "📚" "RapidKit NestJS Project Commands"
|
|
147
|
+
echo ""
|
|
148
|
+
echo "Usage: rapidkit <command> [options]"
|
|
149
|
+
echo ""
|
|
150
|
+
echo "Commands:"
|
|
151
|
+
echo " init 📦 Initialize project (install dependencies)"
|
|
152
|
+
echo " dev 🚀 Start development server with hot reload"
|
|
153
|
+
echo " start ⚡ Start production server"
|
|
154
|
+
echo " build 📦 Build for production"
|
|
155
|
+
echo " test 🧪 Run tests"
|
|
156
|
+
echo " lint 🔧 Lint code"
|
|
157
|
+
echo " format ✨ Format code"
|
|
158
|
+
echo " help 📚 Show this help"
|
|
159
|
+
echo ""
|
|
160
|
+
echo "Options for dev/start:"
|
|
161
|
+
echo " -p, --port <port> Port number (default: 8000)"
|
|
162
|
+
echo " --host <host> Host address (default: 0.0.0.0)"
|
|
163
|
+
echo ""
|
|
164
|
+
echo "💡 Note: This is a demo project. For full RapidKit features:"
|
|
165
|
+
echo " pipx install rapidkit"
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
# Parse command
|
|
169
|
+
COMMAND="${1:-help}"
|
|
170
|
+
shift || true
|
|
171
|
+
|
|
172
|
+
# Parse options
|
|
173
|
+
PORT="8000"
|
|
174
|
+
HOST="0.0.0.0"
|
|
175
|
+
|
|
176
|
+
while [[ $# -gt 0 ]]; do
|
|
177
|
+
case $1 in
|
|
178
|
+
-p|--port)
|
|
179
|
+
PORT="$2"
|
|
180
|
+
shift 2
|
|
181
|
+
;;
|
|
182
|
+
--host)
|
|
183
|
+
HOST="$2"
|
|
184
|
+
shift 2
|
|
185
|
+
;;
|
|
186
|
+
-h|--help)
|
|
187
|
+
cmd_help
|
|
188
|
+
exit 0
|
|
189
|
+
;;
|
|
190
|
+
*)
|
|
191
|
+
shift
|
|
192
|
+
;;
|
|
193
|
+
esac
|
|
194
|
+
done
|
|
195
|
+
|
|
196
|
+
case "$COMMAND" in
|
|
197
|
+
init)
|
|
198
|
+
cmd_init
|
|
199
|
+
;;
|
|
200
|
+
dev)
|
|
201
|
+
cmd_dev "$PORT" "$HOST"
|
|
202
|
+
;;
|
|
203
|
+
start)
|
|
204
|
+
cmd_start "$PORT" "$HOST"
|
|
205
|
+
;;
|
|
206
|
+
build)
|
|
207
|
+
cmd_build
|
|
208
|
+
;;
|
|
209
|
+
test)
|
|
210
|
+
cmd_test
|
|
211
|
+
;;
|
|
212
|
+
lint)
|
|
213
|
+
cmd_lint
|
|
214
|
+
;;
|
|
215
|
+
format)
|
|
216
|
+
cmd_format
|
|
217
|
+
;;
|
|
218
|
+
help|-h|--help)
|
|
219
|
+
cmd_help
|
|
220
|
+
;;
|
|
221
|
+
*)
|
|
222
|
+
echo "❌ Unknown command: $COMMAND"
|
|
223
|
+
echo ""
|
|
224
|
+
cmd_help
|
|
225
|
+
exit 1
|
|
226
|
+
;;
|
|
227
|
+
esac
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
# {{ project_name | replace('-', ' ') | title }}
|
|
2
|
+
|
|
3
|
+
{{ description }}
|
|
4
|
+
|
|
5
|
+
A production-ready NestJS 11 application generated with RapidKit.
|
|
6
|
+
|
|
7
|
+
## 🚀 Getting Started
|
|
8
|
+
|
|
9
|
+
### Prerequisites
|
|
10
|
+
|
|
11
|
+
- Node.js >= 20 (check with `node --version`)
|
|
12
|
+
- {{ package_manager }} package manager
|
|
13
|
+
|
|
14
|
+
### Installation
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
# Install dependencies
|
|
18
|
+
{{ package_manager }} install
|
|
19
|
+
|
|
20
|
+
# Copy environment file
|
|
21
|
+
cp .env.example .env
|
|
22
|
+
|
|
23
|
+
# Start development server
|
|
24
|
+
{{ package_manager }} run dev
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
Your API will be available at `http://localhost:8000`
|
|
28
|
+
API docs available at `http://localhost:8000/docs`
|
|
29
|
+
|
|
30
|
+
## 📚 Available Scripts
|
|
31
|
+
|
|
32
|
+
| Command | Description |
|
|
33
|
+
|---------|-------------|
|
|
34
|
+
| `{{ package_manager }} run dev` | Start development server with hot reload |
|
|
35
|
+
| `{{ package_manager }} run build` | Build for production |
|
|
36
|
+
| `{{ package_manager }} start` | Start production server |
|
|
37
|
+
| `{{ package_manager }} test` | Run unit tests |
|
|
38
|
+
| `{{ package_manager }} run test:e2e` | Run e2e tests |
|
|
39
|
+
| `{{ package_manager }} run test:cov` | Run tests with coverage |
|
|
40
|
+
| `{{ package_manager }} run lint` | Lint and fix code |
|
|
41
|
+
| `{{ package_manager }} run format` | Format code with Prettier |
|
|
42
|
+
|
|
43
|
+
## 📁 Project Structure
|
|
44
|
+
|
|
45
|
+
```
|
|
46
|
+
{{ project_name }}/
|
|
47
|
+
├── src/
|
|
48
|
+
│ ├── main.ts # Application entry point
|
|
49
|
+
│ ├── app.module.ts # Root module
|
|
50
|
+
│ ├── app.controller.ts # Root controller
|
|
51
|
+
│ ├── app.service.ts # Root service
|
|
52
|
+
│ ├── config/ # Configuration module
|
|
53
|
+
│ ├── examples/ # Example feature module
|
|
54
|
+
│ └── modules/ # RapidKit modules
|
|
55
|
+
├── test/ # Test files
|
|
56
|
+
├── package.json # Dependencies
|
|
57
|
+
├── tsconfig.json # TypeScript config
|
|
58
|
+
└── nest-cli.json # NestJS CLI config
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
## 🔧 Configuration
|
|
62
|
+
|
|
63
|
+
Environment variables are managed through `.env` file:
|
|
64
|
+
|
|
65
|
+
- `APP_NAME` - Application name
|
|
66
|
+
- `PORT` - Server port (default: 8000)
|
|
67
|
+
- `HOST` - Server host (default: 0.0.0.0)
|
|
68
|
+
- `NODE_ENV` - Environment (development/production/test)
|
|
69
|
+
|
|
70
|
+
## 🧪 Example API
|
|
71
|
+
|
|
72
|
+
The scaffold includes an example Notes API:
|
|
73
|
+
|
|
74
|
+
```bash
|
|
75
|
+
# Create a note
|
|
76
|
+
curl -X POST http://localhost:8000/examples/notes \
|
|
77
|
+
-H "Content-Type: application/json" \
|
|
78
|
+
-d '{"title":"Hello","body":"World"}'
|
|
79
|
+
|
|
80
|
+
# List all notes
|
|
81
|
+
curl http://localhost:8000/examples/notes
|
|
82
|
+
|
|
83
|
+
# Get health status
|
|
84
|
+
curl http://localhost:8000/health
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
## 📖 Learn More
|
|
88
|
+
|
|
89
|
+
- [NestJS Documentation](https://docs.nestjs.com)
|
|
90
|
+
- [RapidKit Documentation](https://rapidkit.top)
|
|
91
|
+
|
|
92
|
+
## 📄 License
|
|
93
|
+
|
|
94
|
+
This project is licensed under the {{ license }} License.
|
|
95
|
+
|
|
96
|
+
---
|
|
97
|
+
Generated with ❤️ by RapidKit
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { Config } from 'jest';
|
|
2
|
+
|
|
3
|
+
const config: Config = {
|
|
4
|
+
moduleFileExtensions: ['js', 'json', 'ts'],
|
|
5
|
+
rootDir: '.',
|
|
6
|
+
testEnvironment: 'node',
|
|
7
|
+
testRegex: '.*\\.spec.ts$',
|
|
8
|
+
transform: {
|
|
9
|
+
'^.+\\.ts$': 'ts-jest',
|
|
10
|
+
},
|
|
11
|
+
collectCoverageFrom: ['src/**/*.{ts,tsx}', '!src/**/*.module.ts'],
|
|
12
|
+
coverageDirectory: './coverage',
|
|
13
|
+
moduleNameMapper: {
|
|
14
|
+
'^@config/(.*)$': '<rootDir>/src/config/$1',
|
|
15
|
+
'^@modules/(.*)$': '<rootDir>/src/modules/$1',
|
|
16
|
+
'^@shared/(.*)$': '<rootDir>/src/shared/$1',
|
|
17
|
+
},
|
|
18
|
+
setupFiles: ['dotenv/config'],
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
export default config;
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "{{ project_name | replace('_', '-') | lower }}",
|
|
3
|
+
"version": "{{ app_version }}",
|
|
4
|
+
"description": "{{ description }}",
|
|
5
|
+
"license": "{{ license }}",
|
|
6
|
+
"author": "{{ author }}",
|
|
7
|
+
"engines": {
|
|
8
|
+
"node": ">=20"
|
|
9
|
+
},
|
|
10
|
+
"private": true,
|
|
11
|
+
"scripts": {
|
|
12
|
+
"rapidkit": "./.rapidkit/rapidkit",
|
|
13
|
+
"rapidkit:init": "npm install",
|
|
14
|
+
"rapidkit:dev": "./.rapidkit/rapidkit dev",
|
|
15
|
+
"rapidkit:start": "./.rapidkit/rapidkit start",
|
|
16
|
+
"rapidkit:build": "./.rapidkit/rapidkit build",
|
|
17
|
+
"rapidkit:test": "./.rapidkit/rapidkit test",
|
|
18
|
+
"rapidkit:lint": "./.rapidkit/rapidkit lint",
|
|
19
|
+
"rapidkit:format": "./.rapidkit/rapidkit format",
|
|
20
|
+
"start": "node dist/main",
|
|
21
|
+
"dev": "nest start --watch",
|
|
22
|
+
"start:dev": "nest start --watch",
|
|
23
|
+
"start:debug": "nest start --debug --watch",
|
|
24
|
+
"start:prod": "node dist/main",
|
|
25
|
+
"build": "nest build",
|
|
26
|
+
"lint": "eslint \"{src,test}/**/*.ts\" --fix",
|
|
27
|
+
"format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"",
|
|
28
|
+
"test": "jest",
|
|
29
|
+
"test:watch": "jest --watch",
|
|
30
|
+
"test:cov": "jest --coverage",
|
|
31
|
+
"test:e2e": "jest --config ./test/jest-e2e.json"
|
|
32
|
+
},
|
|
33
|
+
"dependencies": {
|
|
34
|
+
"@nestjs/common": "^11.1.6",
|
|
35
|
+
"@nestjs/config": "^4.0.2",
|
|
36
|
+
"@nestjs/core": "^11.1.6",
|
|
37
|
+
"@nestjs/platform-express": "^11.1.6",
|
|
38
|
+
"@nestjs/swagger": "^11.2.3",
|
|
39
|
+
"class-transformer": "^0.5.1",
|
|
40
|
+
"class-validator": "^0.14.0",
|
|
41
|
+
"reflect-metadata": "^0.2.1",
|
|
42
|
+
"rxjs": "^7.8.1",
|
|
43
|
+
"helmet": "^7.0.0",
|
|
44
|
+
"compression": "^1.7.4",
|
|
45
|
+
"winston": "^3.11.0",
|
|
46
|
+
"joi": "^17.12.1",
|
|
47
|
+
"@nestjs/terminus": "^11.0.0",
|
|
48
|
+
"dotenv": "^16.3.1"
|
|
49
|
+
},
|
|
50
|
+
"devDependencies": {
|
|
51
|
+
"@nestjs/cli": "^11.0.10",
|
|
52
|
+
"@nestjs/schematics": "^11.0.7",
|
|
53
|
+
"@nestjs/testing": "^11.1.6",
|
|
54
|
+
"@types/compression": "^1.7.5",
|
|
55
|
+
"@types/express": "^4.17.21",
|
|
56
|
+
"@types/jest": "^29.5.12",
|
|
57
|
+
"@types/node": "^22.8.5",
|
|
58
|
+
"@types/supertest": "^2.0.16",
|
|
59
|
+
"@typescript-eslint/eslint-plugin": "^8.46.1",
|
|
60
|
+
"@typescript-eslint/parser": "^8.46.1",
|
|
61
|
+
"eslint": "^8.57.1",
|
|
62
|
+
"eslint-config-prettier": "^10.1.8",
|
|
63
|
+
"eslint-plugin-import": "^2.32.0",
|
|
64
|
+
"eslint-plugin-prettier": "^5.5.4",
|
|
65
|
+
"jest": "^29.7.0",
|
|
66
|
+
"prettier": "^3.6.2",
|
|
67
|
+
"source-map-support": "^0.5.21",
|
|
68
|
+
"supertest": "^7.1.4",
|
|
69
|
+
"ts-jest": "^29.4.5",
|
|
70
|
+
"ts-loader": "^9.5.4",
|
|
71
|
+
"ts-node": "^10.9.2",
|
|
72
|
+
"tsconfig-paths": "^4.2.0",
|
|
73
|
+
"typescript": "^5.9.3"
|
|
74
|
+
}
|
|
75
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Controller, Get } from '@nestjs/common';
|
|
2
|
+
import { AppService } from './app.service';
|
|
3
|
+
|
|
4
|
+
@Controller()
|
|
5
|
+
export class AppController {
|
|
6
|
+
constructor(private readonly appService: AppService) {}
|
|
7
|
+
|
|
8
|
+
@Get('health')
|
|
9
|
+
getHealth() {
|
|
10
|
+
return this.appService.getHealth();
|
|
11
|
+
}
|
|
12
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { Module } from '@nestjs/common';
|
|
2
|
+
import { ConfigModule } from '@nestjs/config';
|
|
3
|
+
|
|
4
|
+
import configuration from './config/configuration';
|
|
5
|
+
import { validationSchema } from './config/validation';
|
|
6
|
+
import { AppController } from './app.controller';
|
|
7
|
+
import { AppService } from './app.service';
|
|
8
|
+
import { ExamplesModule } from './examples/examples.module';
|
|
9
|
+
|
|
10
|
+
@Module({
|
|
11
|
+
imports: [
|
|
12
|
+
ConfigModule.forRoot({
|
|
13
|
+
isGlobal: true,
|
|
14
|
+
load: [configuration],
|
|
15
|
+
validationSchema,
|
|
16
|
+
expandVariables: true,
|
|
17
|
+
}),
|
|
18
|
+
ExamplesModule,
|
|
19
|
+
],
|
|
20
|
+
controllers: [AppController],
|
|
21
|
+
providers: [AppService],
|
|
22
|
+
})
|
|
23
|
+
export class AppModule {}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { registerAs } from '@nestjs/config';
|
|
2
|
+
|
|
3
|
+
export default registerAs('app', () => ({
|
|
4
|
+
name: process.env.APP_NAME ?? '{{ project_name }}',
|
|
5
|
+
env: process.env.NODE_ENV ?? 'development',
|
|
6
|
+
host: process.env.HOST ?? '0.0.0.0',
|
|
7
|
+
port: parseInt(process.env.PORT ?? '8000', 10),
|
|
8
|
+
logLevel: process.env.LOG_LEVEL ?? 'info',
|
|
9
|
+
}));
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import * as Joi from 'joi';
|
|
2
|
+
|
|
3
|
+
export const validationSchema = Joi.object({
|
|
4
|
+
APP_NAME: Joi.string().default('{{ project_name }}'),
|
|
5
|
+
NODE_ENV: Joi.string().valid('development', 'production', 'test').default('development'),
|
|
6
|
+
HOST: Joi.string().hostname().default('0.0.0.0'),
|
|
7
|
+
PORT: Joi.number().port().default(8000),
|
|
8
|
+
LOG_LEVEL: Joi.string()
|
|
9
|
+
.valid('error', 'warn', 'log', 'debug', 'verbose')
|
|
10
|
+
.default('log'),
|
|
11
|
+
});
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { Body, Controller, Get, Param, ParseIntPipe, Post } from '@nestjs/common';
|
|
2
|
+
|
|
3
|
+
import { CreateNoteDto } from './dto/create-note.dto';
|
|
4
|
+
import { ExamplesService } from './examples.service';
|
|
5
|
+
|
|
6
|
+
@Controller('examples/notes')
|
|
7
|
+
export class ExamplesController {
|
|
8
|
+
constructor(private readonly examplesService: ExamplesService) {}
|
|
9
|
+
|
|
10
|
+
@Post()
|
|
11
|
+
create(@Body() payload: CreateNoteDto) {
|
|
12
|
+
return this.examplesService.create(payload);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
@Get()
|
|
16
|
+
findAll() {
|
|
17
|
+
return this.examplesService.findAll();
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
@Get(':id')
|
|
21
|
+
findOne(@Param('id', ParseIntPipe) id: number) {
|
|
22
|
+
return this.examplesService.findOne(id);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Module } from '@nestjs/common';
|
|
2
|
+
|
|
3
|
+
import { ExamplesController } from './examples.controller';
|
|
4
|
+
import { ExamplesService } from './examples.service';
|
|
5
|
+
|
|
6
|
+
@Module({
|
|
7
|
+
controllers: [ExamplesController],
|
|
8
|
+
providers: [ExamplesService],
|
|
9
|
+
})
|
|
10
|
+
export class ExamplesModule {}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { Injectable, NotFoundException } from '@nestjs/common';
|
|
2
|
+
|
|
3
|
+
import { CreateNoteDto } from './dto/create-note.dto';
|
|
4
|
+
|
|
5
|
+
export interface ExampleNote {
|
|
6
|
+
id: number;
|
|
7
|
+
title: string;
|
|
8
|
+
body: string;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
@Injectable()
|
|
12
|
+
export class ExamplesService {
|
|
13
|
+
private notes: ExampleNote[] = [];
|
|
14
|
+
private sequence = 1;
|
|
15
|
+
|
|
16
|
+
create(payload: CreateNoteDto): ExampleNote {
|
|
17
|
+
const note: ExampleNote = { id: this.sequence++, ...payload };
|
|
18
|
+
this.notes.push(note);
|
|
19
|
+
return note;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
findAll(): ExampleNote[] {
|
|
23
|
+
return [...this.notes];
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
findOne(id: number): ExampleNote {
|
|
27
|
+
const note = this.notes.find((entry) => entry.id === id);
|
|
28
|
+
if (!note) {
|
|
29
|
+
throw new NotFoundException('Note not found');
|
|
30
|
+
}
|
|
31
|
+
return note;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { Logger } from '@nestjs/common';
|
|
2
|
+
import { SwaggerModule, DocumentBuilder } from '@nestjs/swagger';
|
|
3
|
+
import { NestFactory } from '@nestjs/core';
|
|
4
|
+
import helmet from 'helmet';
|
|
5
|
+
import compression from 'compression';
|
|
6
|
+
|
|
7
|
+
import { AppModule } from './app.module';
|
|
8
|
+
|
|
9
|
+
async function bootstrap() {
|
|
10
|
+
const app = await NestFactory.create(AppModule, {
|
|
11
|
+
bufferLogs: true,
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
const logger = new Logger('Bootstrap');
|
|
15
|
+
|
|
16
|
+
app.use(helmet());
|
|
17
|
+
app.use(compression());
|
|
18
|
+
|
|
19
|
+
app.enableCors({
|
|
20
|
+
origin: '*',
|
|
21
|
+
credentials: true,
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
const port = parseInt(process.env.PORT ?? '8000', 10);
|
|
25
|
+
const host = process.env.HOST ?? '0.0.0.0';
|
|
26
|
+
|
|
27
|
+
// Enable Swagger docs in development or when explicitly requested.
|
|
28
|
+
const enableDocs = process.env.RAPIDKIT_ENABLE_SWAGGER === '1' || process.env.NODE_ENV !== 'production';
|
|
29
|
+
if (enableDocs) {
|
|
30
|
+
const config = new DocumentBuilder()
|
|
31
|
+
.setTitle('{{ project_name }} API')
|
|
32
|
+
.setDescription('{{ description }}')
|
|
33
|
+
.setVersion('{{ app_version }}')
|
|
34
|
+
.addBearerAuth()
|
|
35
|
+
.build();
|
|
36
|
+
|
|
37
|
+
const document = SwaggerModule.createDocument(app, config);
|
|
38
|
+
SwaggerModule.setup('docs', app, document);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
await app.listen(port, host);
|
|
42
|
+
|
|
43
|
+
logger.log(`🚀 Application is running on http://${host}:${port}`);
|
|
44
|
+
logger.log(`📚 API docs available at http://${host}:${port}/docs`);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
bootstrap().catch((error) => {
|
|
48
|
+
// eslint-disable-next-line no-console
|
|
49
|
+
console.error('❌ Failed to bootstrap application', error);
|
|
50
|
+
process.exit(1);
|
|
51
|
+
});
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { Test, TestingModule } from '@nestjs/testing';
|
|
2
|
+
|
|
3
|
+
import { AppController } from '../src/app.controller';
|
|
4
|
+
import { AppService } from '../src/app.service';
|
|
5
|
+
|
|
6
|
+
describe('AppController', () => {
|
|
7
|
+
let appController: AppController;
|
|
8
|
+
|
|
9
|
+
beforeEach(async () => {
|
|
10
|
+
const app: TestingModule = await Test.createTestingModule({
|
|
11
|
+
controllers: [AppController],
|
|
12
|
+
providers: [AppService],
|
|
13
|
+
}).compile();
|
|
14
|
+
|
|
15
|
+
appController = app.get<AppController>(AppController);
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
it('should return health status', () => {
|
|
19
|
+
const result = appController.getHealth();
|
|
20
|
+
expect(result).toHaveProperty('status', 'ok');
|
|
21
|
+
});
|
|
22
|
+
});
|