create-nolly-template 1.0.4 → 1.0.6
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/LICENSE +20 -20
- package/README.md +31 -31
- package/dist/index.js +27 -27
- package/dist/registry/web/frontend/vite/base.js +2 -2
- package/package.json +52 -21
- package/templates/web/backend/fastify/base/src/app.ts +52 -52
- package/templates/web/backend/fastify/base/src/controllers/user.controller.ts +11 -11
- package/templates/web/backend/fastify/base/src/index.ts +24 -24
- package/templates/web/backend/fastify/base/src/plugins/health.plugin.ts +5 -5
- package/templates/web/backend/fastify/base/src/routes/user.routes.ts +5 -5
- package/templates/web/backend/fastify/base/src/utils/env.ts +16 -16
- package/templates/web/backend/fastify/base/src/utils/response.ts +4 -4
- package/templates/web/backend/fastify/base/tsconfig.json +19 -19
- package/templates/web/backend/fastify/mongodb/src/plugins/mongo.plugin.ts +52 -52
- package/templates/web/backend/fastify/websocket/src/routes/chat.ws.ts +22 -22
- package/templates/web/backend/fastify/websocket/src/utils/websocket.ts +176 -176
- package/templates/web/frontend/vite/base/index.html +16 -16
- package/templates/web/frontend/vite/base/public/favicon.svg +3 -3
- package/templates/web/frontend/vite/base/src/main.ts +53 -53
- package/templates/web/frontend/vite/base/tsconfig.app.json +25 -25
- package/templates/web/frontend/vite/base/tsconfig.json +6 -6
- package/templates/web/frontend/vite/base/tsconfig.node.json +15 -15
- package/templates/web/frontend/vite/base/vite.config.ts +50 -50
- package/templates/web/frontend/vite/react/src/app.tsx +29 -29
- package/templates/web/frontend/vite/react/src/main.tsx +14 -14
- package/templates/web/frontend/vite/seo/seo.config.ts +23 -23
- package/templates/web/frontend/vite/seo/vite-plugin-seo.ts +85 -85
- package/templates/web/fullstack/nextjs/base/app/favicon.svg +3 -3
- package/templates/web/fullstack/nextjs/base/app/globals.d.ts +8 -8
- package/templates/web/fullstack/nextjs/base/lib/utils.ts +5 -5
- package/CONTRIBUTING.md +0 -142
- package/templates/web/backend/fastify/mongodb/.env +0 -2
package/LICENSE
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2026 Nolly
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Nolly
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
21
|
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,32 +1,32 @@
|
|
|
1
|
-
# 🚀 create-nolly-template
|
|
2
|
-
|
|
3
|
-
All of my opiniated templates in one place. This is a CLI tool to create a new project based on one of my templates.
|
|
4
|
-
|
|
5
|
-
## Install
|
|
6
|
-
```bash
|
|
7
|
-
npm i -g create-nolly-template
|
|
8
|
-
# or pnpm i -g create-nolly-template
|
|
9
|
-
```
|
|
10
|
-
|
|
11
|
-
## Usage
|
|
12
|
-
```bash
|
|
13
|
-
create-nolly-template
|
|
14
|
-
# or npx create-nolly-template
|
|
15
|
-
# or pnpx create-nolly-template
|
|
16
|
-
```
|
|
17
|
-
|
|
18
|
-
## Templates
|
|
19
|
-
You can see the full list of available templates by running `create-nolly-template --list` or `create-nolly-template -l`.
|
|
20
|
-
|
|
21
|
-
## Commands
|
|
22
|
-
- `create-nolly-template` - Create a new project based on one of the templates.
|
|
23
|
-
- `create-nolly-template --list` or `create-nolly-template -l` - List all available templates.
|
|
24
|
-
- `create-nolly-template --help` or `create-nolly-template -h` - Show help message.
|
|
25
|
-
- `create-nolly-template --about` or `create-nolly-template -a` - Show information about the project.
|
|
26
|
-
|
|
27
|
-
## Contributing
|
|
28
|
-
If you want to contribute to this project, feel free to open a pull request or an issue. I would love to see your contributions!
|
|
29
|
-
See the [CONTRIBUTING](CONTRIBUTING.md) guide for more details.
|
|
30
|
-
|
|
31
|
-
## License
|
|
1
|
+
# 🚀 create-nolly-template
|
|
2
|
+
|
|
3
|
+
All of my opiniated templates in one place. This is a CLI tool to create a new project based on one of my templates.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
```bash
|
|
7
|
+
npm i -g create-nolly-template
|
|
8
|
+
# or pnpm i -g create-nolly-template
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
```bash
|
|
13
|
+
create-nolly-template
|
|
14
|
+
# or npx create-nolly-template
|
|
15
|
+
# or pnpx create-nolly-template
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
## Templates
|
|
19
|
+
You can see the full list of available templates by running `create-nolly-template --list` or `create-nolly-template -l`.
|
|
20
|
+
|
|
21
|
+
## Commands
|
|
22
|
+
- `create-nolly-template` - Create a new project based on one of the templates.
|
|
23
|
+
- `create-nolly-template --list` or `create-nolly-template -l` - List all available templates.
|
|
24
|
+
- `create-nolly-template --help` or `create-nolly-template -h` - Show help message.
|
|
25
|
+
- `create-nolly-template --about` or `create-nolly-template -a` - Show information about the project.
|
|
26
|
+
|
|
27
|
+
## Contributing
|
|
28
|
+
If you want to contribute to this project, feel free to open a pull request or an issue. I would love to see your contributions!
|
|
29
|
+
See the [CONTRIBUTING](CONTRIBUTING.md) guide for more details.
|
|
30
|
+
|
|
31
|
+
## License
|
|
32
32
|
This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for more details.
|
package/dist/index.js
CHANGED
|
@@ -4,37 +4,37 @@ import { registry } from './registry/index.js';
|
|
|
4
4
|
import { buildProject } from './builder.js';
|
|
5
5
|
import packageJSON from '../package.json' with { type: 'json' };
|
|
6
6
|
async function printHelp() {
|
|
7
|
-
console.log(`
|
|
8
|
-
🚀 create-nolly-template v${packageJSON.version}
|
|
9
|
-
|
|
10
|
-
${packageJSON.description}
|
|
11
|
-
|
|
12
|
-
Usage:
|
|
13
|
-
create-nolly-template Interactive wizard
|
|
14
|
-
create-nolly-template --help This help
|
|
15
|
-
create-nolly-template --about About & credits
|
|
16
|
-
create-nolly-template --list List all templates
|
|
17
|
-
|
|
18
|
-
Examples:
|
|
19
|
-
pnpx create-nolly-template
|
|
20
|
-
create-nolly-template -l
|
|
7
|
+
console.log(`
|
|
8
|
+
🚀 create-nolly-template v${packageJSON.version}
|
|
9
|
+
|
|
10
|
+
${packageJSON.description}
|
|
11
|
+
|
|
12
|
+
Usage:
|
|
13
|
+
create-nolly-template Interactive wizard
|
|
14
|
+
create-nolly-template --help This help
|
|
15
|
+
create-nolly-template --about About & credits
|
|
16
|
+
create-nolly-template --list List all templates
|
|
17
|
+
|
|
18
|
+
Examples:
|
|
19
|
+
pnpx create-nolly-template
|
|
20
|
+
create-nolly-template -l
|
|
21
21
|
`);
|
|
22
22
|
process.exit(0);
|
|
23
23
|
}
|
|
24
24
|
async function printAbout() {
|
|
25
|
-
console.log(`
|
|
26
|
-
🚀 create-nolly-template v${packageJSON.version}
|
|
27
|
-
|
|
28
|
-
${packageJSON.description}
|
|
29
|
-
|
|
30
|
-
Nolly's templates. Zero-config, TypeScript-first.
|
|
31
|
-
|
|
32
|
-
Templates: Fastify, WebSocket, Swagger, MongoDB, Prisma, and even more !
|
|
33
|
-
Built with: TypeScript, ESM, fs-extra, prompts, and a lot of ❤️
|
|
34
|
-
|
|
35
|
-
Made by Nolly, a passionate full-stack developer and open-source enthusiast.
|
|
36
|
-
GitHub: thenolle/${packageJSON.name}
|
|
37
|
-
License: ${packageJSON.license}
|
|
25
|
+
console.log(`
|
|
26
|
+
🚀 create-nolly-template v${packageJSON.version}
|
|
27
|
+
|
|
28
|
+
${packageJSON.description}
|
|
29
|
+
|
|
30
|
+
Nolly's templates. Zero-config, TypeScript-first.
|
|
31
|
+
|
|
32
|
+
Templates: Fastify, WebSocket, Swagger, MongoDB, Prisma, and even more !
|
|
33
|
+
Built with: TypeScript, ESM, fs-extra, prompts, and a lot of ❤️
|
|
34
|
+
|
|
35
|
+
Made by Nolly, a passionate full-stack developer and open-source enthusiast.
|
|
36
|
+
GitHub: thenolle/${packageJSON.name}
|
|
37
|
+
License: ${packageJSON.license}
|
|
38
38
|
`);
|
|
39
39
|
process.exit(0);
|
|
40
40
|
}
|
package/package.json
CHANGED
|
@@ -1,40 +1,50 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "create-nolly-template",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.6",
|
|
4
4
|
"description": "All of my opiniated templates in one place. This is a CLI tool to create a new project based on one of my templates.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"author": "Nolly",
|
|
7
|
+
"homepage": "https://github.com/thenolle/create-nolly-template#readme",
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "https://github.com/TheNolle/create-nolly-template"
|
|
11
|
+
},
|
|
12
|
+
"bugs": {
|
|
13
|
+
"url": "https://github.com/thenolle/create-nolly-template/issues"
|
|
14
|
+
},
|
|
5
15
|
"keywords": [
|
|
6
|
-
"
|
|
16
|
+
"boilerplate",
|
|
17
|
+
"cli",
|
|
7
18
|
"fastify",
|
|
8
|
-
"react",
|
|
9
|
-
"next.js",
|
|
10
19
|
"fullstack",
|
|
11
|
-
"
|
|
12
|
-
"swagger",
|
|
20
|
+
"next.js",
|
|
13
21
|
"prisma",
|
|
22
|
+
"react",
|
|
23
|
+
"swagger",
|
|
24
|
+
"template",
|
|
14
25
|
"typescript",
|
|
15
|
-
"
|
|
16
|
-
"boilerplate"
|
|
26
|
+
"vite"
|
|
17
27
|
],
|
|
18
|
-
"
|
|
19
|
-
"
|
|
28
|
+
"type": "module",
|
|
29
|
+
"sideEffects": false,
|
|
30
|
+
"engines": {
|
|
31
|
+
"node": ">=20",
|
|
32
|
+
"pnpm": ">=9.10.0"
|
|
33
|
+
},
|
|
20
34
|
"bin": {
|
|
21
35
|
"create-nolly-template": "dist/index.js"
|
|
22
36
|
},
|
|
37
|
+
"exports": {
|
|
38
|
+
".": "./dist/index.js"
|
|
39
|
+
},
|
|
23
40
|
"files": [
|
|
24
41
|
"dist",
|
|
25
42
|
"templates",
|
|
26
|
-
"package.json",
|
|
27
43
|
"README.md",
|
|
28
44
|
"LICENSE",
|
|
29
|
-
"CONTRIBUTING.md"
|
|
45
|
+
"CONTRIBUTING.md",
|
|
46
|
+
"package.json"
|
|
30
47
|
],
|
|
31
|
-
"engines": {
|
|
32
|
-
"node": ">=20"
|
|
33
|
-
},
|
|
34
|
-
"publishConfig": {
|
|
35
|
-
"registry": "https://registry.npmjs.org/"
|
|
36
|
-
},
|
|
37
|
-
"type": "module",
|
|
38
48
|
"dependencies": {
|
|
39
49
|
"fs-extra": "^11.3.4",
|
|
40
50
|
"prompts": "^2.4.2"
|
|
@@ -46,9 +56,30 @@
|
|
|
46
56
|
"tsx": "^4.21.0",
|
|
47
57
|
"typescript": "^5.9.3"
|
|
48
58
|
},
|
|
59
|
+
"publishConfig": {
|
|
60
|
+
"registry": "https://registry.npmjs.org/"
|
|
61
|
+
},
|
|
62
|
+
"funding": [
|
|
63
|
+
{
|
|
64
|
+
"type": "github",
|
|
65
|
+
"url": "https://github.com/sponsors/thenolle"
|
|
66
|
+
},
|
|
67
|
+
{
|
|
68
|
+
"type": "ko-fi",
|
|
69
|
+
"url": "https://ko-fi.com/nollycafe"
|
|
70
|
+
},
|
|
71
|
+
{
|
|
72
|
+
"type": "patreon",
|
|
73
|
+
"url": "https://www.patreon.com/_nolly"
|
|
74
|
+
},
|
|
75
|
+
{
|
|
76
|
+
"type": "paypal",
|
|
77
|
+
"url": "https://paypal.me/nollyscafe"
|
|
78
|
+
}
|
|
79
|
+
],
|
|
49
80
|
"scripts": {
|
|
50
81
|
"build": "rm -rf dist && tsc --build tsconfig.cli.json",
|
|
51
|
-
"
|
|
52
|
-
"
|
|
82
|
+
"dev": "tsx src/index.ts",
|
|
83
|
+
"start": "node dist/index.js"
|
|
53
84
|
}
|
|
54
85
|
}
|
|
@@ -1,53 +1,53 @@
|
|
|
1
|
-
import fastify from 'fastify'
|
|
2
|
-
import cors from '@fastify/cors'
|
|
3
|
-
import helmet from '@fastify/helmet'
|
|
4
|
-
import path from 'path'
|
|
5
|
-
import { fileURLToPath, pathToFileURL } from 'url'
|
|
6
|
-
import fg from 'fast-glob'
|
|
7
|
-
import { env } from './utils/env'
|
|
8
|
-
import { sendResponse } from './utils/response'
|
|
9
|
-
|
|
10
|
-
const __filename = fileURLToPath(import.meta.url)
|
|
11
|
-
const __dirname = path.dirname(__filename)
|
|
12
|
-
|
|
13
|
-
async function autoRegister(app: ReturnType<typeof fastify>, pattern: string, prefix: string = '') {
|
|
14
|
-
const joined = path.join(__dirname, pattern).replace(/\\/g, '/')
|
|
15
|
-
const files = fg.sync(joined)
|
|
16
|
-
await Promise.all(files.map(async (file) => {
|
|
17
|
-
const module = await import(pathToFileURL(file).href)
|
|
18
|
-
const fn = module.default || module[Object.keys(module)[0]]
|
|
19
|
-
if (typeof fn === 'function') void app.register(fn, { prefix })
|
|
20
|
-
}))
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export async function buildApp() {
|
|
24
|
-
const isDev = env.NODE_ENV === 'development'
|
|
25
|
-
const app = fastify({
|
|
26
|
-
logger: {
|
|
27
|
-
level: 'info',
|
|
28
|
-
transport: isDev ? {
|
|
29
|
-
target: 'pino-pretty',
|
|
30
|
-
options: {
|
|
31
|
-
colorize: true,
|
|
32
|
-
translateTime: 'HH:MM:ss',
|
|
33
|
-
ignore: 'pid,hostname',
|
|
34
|
-
},
|
|
35
|
-
} : undefined,
|
|
36
|
-
},
|
|
37
|
-
})
|
|
38
|
-
|
|
39
|
-
app.register(cors, { origin: true })
|
|
40
|
-
app.register(helmet)
|
|
41
|
-
|
|
42
|
-
await autoRegister(app, 'plugins/**/*.plugin.{ts,js}')
|
|
43
|
-
await autoRegister(app, 'routes/**/*.routes.{ts,js}')
|
|
44
|
-
|
|
45
|
-
app.setNotFoundHandler((_request, reply) => sendResponse(reply, 404, { error: 'Route not found' }))
|
|
46
|
-
app.setErrorHandler((error: any, _request, reply) => {
|
|
47
|
-
const statusCode = error?.statusCode ?? 500
|
|
48
|
-
app.log.error(error)
|
|
49
|
-
return sendResponse(reply, statusCode, { error: statusCode >= 500 ? 'Internal Server Error' : error.message })
|
|
50
|
-
})
|
|
51
|
-
|
|
52
|
-
return app
|
|
1
|
+
import fastify from 'fastify'
|
|
2
|
+
import cors from '@fastify/cors'
|
|
3
|
+
import helmet from '@fastify/helmet'
|
|
4
|
+
import path from 'path'
|
|
5
|
+
import { fileURLToPath, pathToFileURL } from 'url'
|
|
6
|
+
import fg from 'fast-glob'
|
|
7
|
+
import { env } from './utils/env'
|
|
8
|
+
import { sendResponse } from './utils/response'
|
|
9
|
+
|
|
10
|
+
const __filename = fileURLToPath(import.meta.url)
|
|
11
|
+
const __dirname = path.dirname(__filename)
|
|
12
|
+
|
|
13
|
+
async function autoRegister(app: ReturnType<typeof fastify>, pattern: string, prefix: string = '') {
|
|
14
|
+
const joined = path.join(__dirname, pattern).replace(/\\/g, '/')
|
|
15
|
+
const files = fg.sync(joined)
|
|
16
|
+
await Promise.all(files.map(async (file) => {
|
|
17
|
+
const module = await import(pathToFileURL(file).href)
|
|
18
|
+
const fn = module.default || module[Object.keys(module)[0]]
|
|
19
|
+
if (typeof fn === 'function') void app.register(fn, { prefix })
|
|
20
|
+
}))
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export async function buildApp() {
|
|
24
|
+
const isDev = env.NODE_ENV === 'development'
|
|
25
|
+
const app = fastify({
|
|
26
|
+
logger: {
|
|
27
|
+
level: 'info',
|
|
28
|
+
transport: isDev ? {
|
|
29
|
+
target: 'pino-pretty',
|
|
30
|
+
options: {
|
|
31
|
+
colorize: true,
|
|
32
|
+
translateTime: 'HH:MM:ss',
|
|
33
|
+
ignore: 'pid,hostname',
|
|
34
|
+
},
|
|
35
|
+
} : undefined,
|
|
36
|
+
},
|
|
37
|
+
})
|
|
38
|
+
|
|
39
|
+
app.register(cors, { origin: true })
|
|
40
|
+
app.register(helmet)
|
|
41
|
+
|
|
42
|
+
await autoRegister(app, 'plugins/**/*.plugin.{ts,js}')
|
|
43
|
+
await autoRegister(app, 'routes/**/*.routes.{ts,js}')
|
|
44
|
+
|
|
45
|
+
app.setNotFoundHandler((_request, reply) => sendResponse(reply, 404, { error: 'Route not found' }))
|
|
46
|
+
app.setErrorHandler((error: any, _request, reply) => {
|
|
47
|
+
const statusCode = error?.statusCode ?? 500
|
|
48
|
+
app.log.error(error)
|
|
49
|
+
return sendResponse(reply, statusCode, { error: statusCode >= 500 ? 'Internal Server Error' : error.message })
|
|
50
|
+
})
|
|
51
|
+
|
|
52
|
+
return app
|
|
53
53
|
}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import { FastifyRequest, FastifyReply } from 'fastify'
|
|
2
|
-
import { z } from 'zod'
|
|
3
|
-
import { sendResponse } from '../utils/response'
|
|
4
|
-
|
|
5
|
-
const userSchema = z.object({ id: z.uuid() })
|
|
6
|
-
|
|
7
|
-
export async function getUserHandler(request: FastifyRequest<{ Params: { id: string } }>, reply: FastifyReply) {
|
|
8
|
-
const parseResult = userSchema.safeParse(request.params)
|
|
9
|
-
if (!parseResult.success) return sendResponse(reply, 400, { error: 'Invalid user ID' })
|
|
10
|
-
const user = { id: parseResult.data.id, name: 'Nolly Example' }
|
|
11
|
-
return sendResponse(reply, 200, user)
|
|
1
|
+
import { FastifyRequest, FastifyReply } from 'fastify'
|
|
2
|
+
import { z } from 'zod'
|
|
3
|
+
import { sendResponse } from '../utils/response'
|
|
4
|
+
|
|
5
|
+
const userSchema = z.object({ id: z.uuid() })
|
|
6
|
+
|
|
7
|
+
export async function getUserHandler(request: FastifyRequest<{ Params: { id: string } }>, reply: FastifyReply) {
|
|
8
|
+
const parseResult = userSchema.safeParse(request.params)
|
|
9
|
+
if (!parseResult.success) return sendResponse(reply, 400, { error: 'Invalid user ID' })
|
|
10
|
+
const user = { id: parseResult.data.id, name: 'Nolly Example' }
|
|
11
|
+
return sendResponse(reply, 200, user)
|
|
12
12
|
}
|
|
@@ -1,25 +1,25 @@
|
|
|
1
|
-
import 'dotenv/config'
|
|
2
|
-
import { buildApp } from './app'
|
|
3
|
-
import { env } from './utils/env'
|
|
4
|
-
|
|
5
|
-
const PORT = parseInt(env.PORT, 10)
|
|
6
|
-
const HOST = env.HOST
|
|
7
|
-
|
|
8
|
-
buildApp()
|
|
9
|
-
.then((app) => {
|
|
10
|
-
const shutdown = async (signal: string) => {
|
|
11
|
-
app.log.info(`Received ${signal}, shutting down...`)
|
|
12
|
-
await app.close()
|
|
13
|
-
process.exit(0)
|
|
14
|
-
}
|
|
15
|
-
process.on('SIGINT', () => shutdown('SIGINT'))
|
|
16
|
-
process.on('SIGTERM', () => shutdown('SIGTERM'))
|
|
17
|
-
app.listen({ port: PORT, host: HOST }).catch((error) => {
|
|
18
|
-
app.log.error('Error starting server:', error)
|
|
19
|
-
process.exit(1)
|
|
20
|
-
})
|
|
21
|
-
})
|
|
22
|
-
.catch((error) => {
|
|
23
|
-
console.error('Error building app:', error)
|
|
24
|
-
process.exit(1)
|
|
1
|
+
import 'dotenv/config'
|
|
2
|
+
import { buildApp } from './app'
|
|
3
|
+
import { env } from './utils/env'
|
|
4
|
+
|
|
5
|
+
const PORT = parseInt(env.PORT, 10)
|
|
6
|
+
const HOST = env.HOST
|
|
7
|
+
|
|
8
|
+
buildApp()
|
|
9
|
+
.then((app) => {
|
|
10
|
+
const shutdown = async (signal: string) => {
|
|
11
|
+
app.log.info(`Received ${signal}, shutting down...`)
|
|
12
|
+
await app.close()
|
|
13
|
+
process.exit(0)
|
|
14
|
+
}
|
|
15
|
+
process.on('SIGINT', () => shutdown('SIGINT'))
|
|
16
|
+
process.on('SIGTERM', () => shutdown('SIGTERM'))
|
|
17
|
+
app.listen({ port: PORT, host: HOST }).catch((error) => {
|
|
18
|
+
app.log.error('Error starting server:', error)
|
|
19
|
+
process.exit(1)
|
|
20
|
+
})
|
|
21
|
+
})
|
|
22
|
+
.catch((error) => {
|
|
23
|
+
console.error('Error building app:', error)
|
|
24
|
+
process.exit(1)
|
|
25
25
|
})
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { FastifyInstance } from 'fastify'
|
|
2
|
-
import { sendResponse } from '../utils/response'
|
|
3
|
-
|
|
4
|
-
export default async function healthPlugin(app: FastifyInstance) {
|
|
5
|
-
app.get('/health', async (_request, reply) => sendResponse(reply, 200, { status: 'ok', uptime: process.uptime() }))
|
|
1
|
+
import { FastifyInstance } from 'fastify'
|
|
2
|
+
import { sendResponse } from '../utils/response'
|
|
3
|
+
|
|
4
|
+
export default async function healthPlugin(app: FastifyInstance) {
|
|
5
|
+
app.get('/health', async (_request, reply) => sendResponse(reply, 200, { status: 'ok', uptime: process.uptime() }))
|
|
6
6
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { FastifyInstance } from 'fastify'
|
|
2
|
-
import { getUserHandler } from '../controllers/user.controller'
|
|
3
|
-
|
|
4
|
-
export default async function userRoutes(app: FastifyInstance) {
|
|
5
|
-
app.get('/users/:id', getUserHandler)
|
|
1
|
+
import { FastifyInstance } from 'fastify'
|
|
2
|
+
import { getUserHandler } from '../controllers/user.controller'
|
|
3
|
+
|
|
4
|
+
export default async function userRoutes(app: FastifyInstance) {
|
|
5
|
+
app.get('/users/:id', getUserHandler)
|
|
6
6
|
}
|
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
import 'dotenv/config'
|
|
2
|
-
import { z } from 'zod'
|
|
3
|
-
|
|
4
|
-
const envSchema = z.object({
|
|
5
|
-
PORT: z.string().optional().default('4000'),
|
|
6
|
-
HOST: z.string().optional().default('0.0.0.0'),
|
|
7
|
-
NODE_ENV: z.enum(['development', 'production', 'test']).default('development'),
|
|
8
|
-
})
|
|
9
|
-
|
|
10
|
-
const result = envSchema.safeParse(process.env)
|
|
11
|
-
if (!result.success) {
|
|
12
|
-
console.error('❌ Invalid environment variables:')
|
|
13
|
-
const flattened = z.treeifyError(result.error)
|
|
14
|
-
console.error(flattened.errors)
|
|
15
|
-
process.exit(1)
|
|
16
|
-
}
|
|
1
|
+
import 'dotenv/config'
|
|
2
|
+
import { z } from 'zod'
|
|
3
|
+
|
|
4
|
+
const envSchema = z.object({
|
|
5
|
+
PORT: z.string().optional().default('4000'),
|
|
6
|
+
HOST: z.string().optional().default('0.0.0.0'),
|
|
7
|
+
NODE_ENV: z.enum(['development', 'production', 'test']).default('development'),
|
|
8
|
+
})
|
|
9
|
+
|
|
10
|
+
const result = envSchema.safeParse(process.env)
|
|
11
|
+
if (!result.success) {
|
|
12
|
+
console.error('❌ Invalid environment variables:')
|
|
13
|
+
const flattened = z.treeifyError(result.error)
|
|
14
|
+
console.error(flattened.errors)
|
|
15
|
+
process.exit(1)
|
|
16
|
+
}
|
|
17
17
|
export const env = result.data
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { FastifyReply } from 'fastify'
|
|
2
|
-
|
|
3
|
-
export function sendResponse<T>(reply: FastifyReply, statusCode: number, data: T) {
|
|
4
|
-
return reply.status(statusCode).send({ success: statusCode < 400, data })
|
|
1
|
+
import { FastifyReply } from 'fastify'
|
|
2
|
+
|
|
3
|
+
export function sendResponse<T>(reply: FastifyReply, statusCode: number, data: T) {
|
|
4
|
+
return reply.status(statusCode).send({ success: statusCode < 400, data })
|
|
5
5
|
}
|
|
@@ -1,20 +1,20 @@
|
|
|
1
|
-
{
|
|
2
|
-
"compilerOptions": {
|
|
3
|
-
"target": "ES2022",
|
|
4
|
-
"useDefineForClassFields": true,
|
|
5
|
-
"lib": [ "ES2022" ],
|
|
6
|
-
"module": "ESNext",
|
|
7
|
-
"moduleResolution": "bundler",
|
|
8
|
-
"allowImportingTsExtensions": true,
|
|
9
|
-
"isolatedModules": true,
|
|
10
|
-
"moduleDetection": "force",
|
|
11
|
-
"noEmit": true,
|
|
12
|
-
"strict": true,
|
|
13
|
-
"noUnusedLocals": true,
|
|
14
|
-
"noUnusedParameters": true,
|
|
15
|
-
"noFallthroughCasesInSwitch": true,
|
|
16
|
-
"noUncheckedSideEffectImports": true,
|
|
17
|
-
"skipLibCheck": true
|
|
18
|
-
},
|
|
19
|
-
"include": [ "src" ]
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "ES2022",
|
|
4
|
+
"useDefineForClassFields": true,
|
|
5
|
+
"lib": [ "ES2022" ],
|
|
6
|
+
"module": "ESNext",
|
|
7
|
+
"moduleResolution": "bundler",
|
|
8
|
+
"allowImportingTsExtensions": true,
|
|
9
|
+
"isolatedModules": true,
|
|
10
|
+
"moduleDetection": "force",
|
|
11
|
+
"noEmit": true,
|
|
12
|
+
"strict": true,
|
|
13
|
+
"noUnusedLocals": true,
|
|
14
|
+
"noUnusedParameters": true,
|
|
15
|
+
"noFallthroughCasesInSwitch": true,
|
|
16
|
+
"noUncheckedSideEffectImports": true,
|
|
17
|
+
"skipLibCheck": true
|
|
18
|
+
},
|
|
19
|
+
"include": [ "src" ]
|
|
20
20
|
}
|