bootifyjs 1.1.9 ā 1.2.0
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/api.d.ts +4 -0
- package/dist/api.d.ts.map +1 -1
- package/dist/api.js +24 -9
- package/dist/api.js.map +1 -1
- package/dist/auth/AuthManager.d.ts +68 -0
- package/dist/auth/AuthManager.d.ts.map +1 -0
- package/dist/auth/AuthManager.js +239 -0
- package/dist/auth/AuthManager.js.map +1 -0
- package/dist/auth/examples/basic-usage.d.ts +29 -0
- package/dist/auth/examples/basic-usage.d.ts.map +1 -0
- package/dist/auth/examples/basic-usage.js +390 -0
- package/dist/auth/examples/basic-usage.js.map +1 -0
- package/dist/auth/index.d.ts +72 -0
- package/dist/auth/index.d.ts.map +1 -0
- package/dist/auth/index.js +118 -0
- package/dist/auth/index.js.map +1 -0
- package/dist/auth/middleware/AuthMiddleware.d.ts +110 -0
- package/dist/auth/middleware/AuthMiddleware.d.ts.map +1 -0
- package/dist/auth/middleware/AuthMiddleware.js +336 -0
- package/dist/auth/middleware/AuthMiddleware.js.map +1 -0
- package/dist/auth/storage/RedisTokenStorage.d.ts +92 -0
- package/dist/auth/storage/RedisTokenStorage.d.ts.map +1 -0
- package/dist/auth/storage/RedisTokenStorage.js +207 -0
- package/dist/auth/storage/RedisTokenStorage.js.map +1 -0
- package/dist/auth/strategies/ApiKeyStrategy.d.ts +64 -0
- package/dist/auth/strategies/ApiKeyStrategy.d.ts.map +1 -0
- package/dist/auth/strategies/ApiKeyStrategy.js +391 -0
- package/dist/auth/strategies/ApiKeyStrategy.js.map +1 -0
- package/dist/auth/strategies/JwtStrategy.d.ts +46 -0
- package/dist/auth/strategies/JwtStrategy.d.ts.map +1 -0
- package/dist/auth/strategies/JwtStrategy.js +310 -0
- package/dist/auth/strategies/JwtStrategy.js.map +1 -0
- package/dist/auth/types.d.ts +130 -0
- package/dist/auth/types.d.ts.map +1 -0
- package/dist/auth/types.js +50 -0
- package/dist/auth/types.js.map +1 -0
- package/dist/config/AppConfig.d.ts +3 -3
- package/dist/config/AppConfig.d.ts.map +1 -1
- package/dist/config/AppConfig.js +9 -2
- package/dist/config/AppConfig.js.map +1 -1
- package/dist/constants/index.d.ts +61 -0
- package/dist/constants/index.d.ts.map +1 -0
- package/dist/constants/index.js +75 -0
- package/dist/constants/index.js.map +1 -0
- package/dist/core/decorators.d.ts +7 -7
- package/dist/core/decorators.d.ts.map +1 -1
- package/dist/core/decorators.js +8 -7
- package/dist/core/decorators.js.map +1 -1
- package/dist/core/di-container.d.ts +1 -1
- package/dist/core/di-container.d.ts.map +1 -1
- package/dist/core/di-container.js +3 -3
- package/dist/core/di-container.js.map +1 -1
- package/dist/events/event-bus.service.d.ts.map +1 -1
- package/dist/events/event-bus.service.js +2 -0
- package/dist/events/event-bus.service.js.map +1 -1
- package/dist/examples/auth/auth.middleware.d.ts +27 -0
- package/dist/examples/auth/auth.middleware.d.ts.map +1 -0
- package/dist/examples/auth/auth.middleware.js +187 -0
- package/dist/examples/auth/auth.middleware.js.map +1 -0
- package/dist/examples/auth/authorization.middleware.d.ts +1 -0
- package/dist/examples/auth/authorization.middleware.d.ts.map +1 -0
- package/dist/examples/auth/authorization.middleware.js +2 -0
- package/dist/examples/auth/authorization.middleware.js.map +1 -0
- package/dist/examples/auth/context.extractor.d.ts +1 -0
- package/dist/examples/auth/context.extractor.d.ts.map +1 -0
- package/dist/examples/auth/context.extractor.js +2 -0
- package/dist/examples/auth/context.extractor.js.map +1 -0
- package/dist/examples/auth/example.d.ts +1 -0
- package/dist/examples/auth/example.d.ts.map +1 -0
- package/dist/examples/auth/example.js +2 -0
- package/dist/examples/auth/example.js.map +1 -0
- package/dist/examples/auth/provider.d.ts +1 -0
- package/dist/examples/auth/provider.d.ts.map +1 -0
- package/dist/examples/auth/provider.js +2 -0
- package/dist/examples/auth/provider.js.map +1 -0
- package/dist/examples/auth/users.d.ts +1 -0
- package/dist/examples/auth/users.d.ts.map +1 -0
- package/dist/examples/auth/users.js +2 -0
- package/dist/examples/auth/users.js.map +1 -0
- package/dist/examples/authorization-examples.d.ts +67 -0
- package/dist/examples/authorization-examples.d.ts.map +1 -0
- package/dist/examples/authorization-examples.js +202 -0
- package/dist/examples/authorization-examples.js.map +1 -0
- package/dist/examples/controllers/auth.controller.d.ts +64 -0
- package/dist/examples/controllers/auth.controller.d.ts.map +1 -0
- package/dist/examples/controllers/auth.controller.js +284 -0
- package/dist/examples/controllers/auth.controller.js.map +1 -0
- package/dist/examples/controllers/health.controller.d.ts +1 -0
- package/dist/examples/controllers/health.controller.d.ts.map +1 -1
- package/dist/examples/controllers/health.controller.js +6 -0
- package/dist/examples/controllers/health.controller.js.map +1 -1
- package/dist/examples/controllers/todo-updated.controller.d.ts +103 -0
- package/dist/examples/controllers/todo-updated.controller.d.ts.map +1 -0
- package/dist/examples/controllers/todo-updated.controller.js +328 -0
- package/dist/examples/controllers/todo-updated.controller.js.map +1 -0
- package/dist/examples/controllers/todo-with-jwt-auth.controller.d.ts +114 -0
- package/dist/examples/controllers/todo-with-jwt-auth.controller.d.ts.map +1 -0
- package/dist/examples/controllers/todo-with-jwt-auth.controller.js +329 -0
- package/dist/examples/controllers/todo-with-jwt-auth.controller.js.map +1 -0
- package/dist/examples/controllers/todo.controller.d.ts +4 -2
- package/dist/examples/controllers/todo.controller.d.ts.map +1 -1
- package/dist/examples/controllers/todo.controller.js +44 -18
- package/dist/examples/controllers/todo.controller.js.map +1 -1
- package/dist/examples/events/TodoEventHandler.d.ts +4 -1
- package/dist/examples/events/TodoEventHandler.d.ts.map +1 -1
- package/dist/examples/events/TodoEventHandler.js +8 -4
- package/dist/examples/events/TodoEventHandler.js.map +1 -1
- package/dist/examples/global-middleware-example.d.ts +2 -0
- package/dist/examples/global-middleware-example.d.ts.map +1 -0
- package/dist/examples/global-middleware-example.js +94 -0
- package/dist/examples/global-middleware-example.js.map +1 -0
- package/dist/examples/index.d.ts.map +1 -1
- package/dist/examples/index.js +81 -25
- package/dist/examples/index.js.map +1 -1
- package/dist/examples/jwt-auth-example.d.ts +47 -0
- package/dist/examples/jwt-auth-example.d.ts.map +1 -0
- package/dist/examples/jwt-auth-example.js +316 -0
- package/dist/examples/jwt-auth-example.js.map +1 -0
- package/dist/examples/services/todo.service.d.ts +3 -2
- package/dist/examples/services/todo.service.d.ts.map +1 -1
- package/dist/examples/services/todo.service.js +12 -2
- package/dist/examples/services/todo.service.js.map +1 -1
- package/dist/examples/services/user.service.d.ts +99 -0
- package/dist/examples/services/user.service.d.ts.map +1 -0
- package/dist/examples/services/user.service.js +281 -0
- package/dist/examples/services/user.service.js.map +1 -0
- package/dist/examples/simple-auth-example.d.ts +7 -0
- package/dist/examples/simple-auth-example.d.ts.map +1 -0
- package/dist/examples/simple-auth-example.js +106 -0
- package/dist/examples/simple-auth-example.js.map +1 -0
- package/dist/examples/test-auth-flow.d.ts +56 -0
- package/dist/examples/test-auth-flow.d.ts.map +1 -0
- package/dist/examples/test-auth-flow.js +449 -0
- package/dist/examples/test-auth-flow.js.map +1 -0
- package/dist/examples/todos/schema.d.ts +8 -8
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/logging/config/logging.config.d.ts +0 -32
- package/dist/logging/config/logging.config.d.ts.map +1 -1
- package/dist/logging/config/logging.config.js +43 -49
- package/dist/logging/config/logging.config.js.map +1 -1
- package/dist/logging/core/logger.d.ts +1 -0
- package/dist/logging/core/logger.d.ts.map +1 -1
- package/dist/logging/core/logger.js +3 -0
- package/dist/logging/core/logger.js.map +1 -1
- package/dist/logging/core/logger.provider.d.ts.map +1 -1
- package/dist/logging/core/logger.provider.js +24 -12
- package/dist/logging/core/logger.provider.js.map +1 -1
- package/dist/logging/core/startup.logger.d.ts +1 -1
- package/dist/logging/core/startup.logger.d.ts.map +1 -1
- package/dist/logging/core/startup.logger.js +6 -3
- package/dist/logging/core/startup.logger.js.map +1 -1
- package/dist/logging/core/tracing.service.d.ts +32 -0
- package/dist/logging/core/tracing.service.d.ts.map +1 -0
- package/dist/logging/core/tracing.service.js +165 -0
- package/dist/logging/core/tracing.service.js.map +1 -0
- package/dist/logging/index.d.ts +1 -1
- package/dist/logging/index.d.ts.map +1 -1
- package/dist/logging/index.js +3 -2
- package/dist/logging/index.js.map +1 -1
- package/dist/middleware/auth-context.extractor.d.ts +5 -0
- package/dist/middleware/auth-context.extractor.d.ts.map +1 -0
- package/dist/middleware/auth-context.extractor.js +114 -0
- package/dist/middleware/auth-context.extractor.js.map +1 -0
- package/dist/middleware/auth.middleware.d.ts +16 -2
- package/dist/middleware/auth.middleware.d.ts.map +1 -1
- package/dist/middleware/auth.middleware.js +110 -13
- package/dist/middleware/auth.middleware.js.map +1 -1
- package/dist/middleware/authorization.middleware.d.ts +21 -0
- package/dist/middleware/authorization.middleware.d.ts.map +1 -0
- package/dist/middleware/authorization.middleware.js +55 -0
- package/dist/middleware/authorization.middleware.js.map +1 -0
- package/dist/middleware/context.middleware.d.ts +12 -2
- package/dist/middleware/context.middleware.d.ts.map +1 -1
- package/dist/middleware/context.middleware.js +43 -17
- package/dist/middleware/context.middleware.js.map +1 -1
- package/dist/middleware/index.d.ts +1 -0
- package/dist/middleware/index.d.ts.map +1 -1
- package/dist/middleware/tracing.middleware.d.ts +15 -0
- package/dist/middleware/tracing.middleware.d.ts.map +1 -0
- package/dist/middleware/tracing.middleware.js +36 -0
- package/dist/middleware/tracing.middleware.js.map +1 -0
- package/package.json +5 -1
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.startAppWithGlobalMiddlewares = startAppWithGlobalMiddlewares;
|
|
13
|
+
const index_1 = require("../index");
|
|
14
|
+
const decorators_1 = require("../core/decorators");
|
|
15
|
+
// Example middleware implementations
|
|
16
|
+
const authMiddleware = async (request, reply) => {
|
|
17
|
+
console.log('š Auth middleware executed');
|
|
18
|
+
request.user = { id: 1, username: 'testuser' };
|
|
19
|
+
};
|
|
20
|
+
const rateLimitMiddleware = async (request, reply) => {
|
|
21
|
+
console.log('ā±ļø Rate limit middleware executed');
|
|
22
|
+
// Add rate limiting logic here
|
|
23
|
+
// For example: check request count per IP, implement sliding window, etc.
|
|
24
|
+
// Example: Simple rate limiting check
|
|
25
|
+
const clientIP = request.ip;
|
|
26
|
+
console.log(`Rate limiting check for IP: ${clientIP}`);
|
|
27
|
+
};
|
|
28
|
+
const loggingMiddleware = async (request, reply) => {
|
|
29
|
+
console.log('š Custom logging middleware executed');
|
|
30
|
+
// Add custom logging logic here
|
|
31
|
+
// For example: log request details, performance metrics, etc.
|
|
32
|
+
console.log(`${request.method} ${request.url} - User-Agent: ${request.headers['user-agent']}`);
|
|
33
|
+
};
|
|
34
|
+
const corsMiddleware = async (request, reply) => {
|
|
35
|
+
console.log('š CORS middleware executed');
|
|
36
|
+
// Add CORS headers
|
|
37
|
+
reply.header('Access-Control-Allow-Origin', '*');
|
|
38
|
+
reply.header('Access-Control-Allow-Methods', 'GET, POST, PUT, DELETE, OPTIONS');
|
|
39
|
+
reply.header('Access-Control-Allow-Headers', 'Content-Type, Authorization');
|
|
40
|
+
};
|
|
41
|
+
let UserController = class UserController {
|
|
42
|
+
getUsers() {
|
|
43
|
+
return {
|
|
44
|
+
message: 'Users retrieved successfully',
|
|
45
|
+
users: [
|
|
46
|
+
{ id: 1, name: 'John Doe' },
|
|
47
|
+
{ id: 2, name: 'Jane Smith' }
|
|
48
|
+
]
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
getUserById() {
|
|
52
|
+
return {
|
|
53
|
+
message: 'User retrieved successfully',
|
|
54
|
+
user: { id: 1, name: 'John Doe' }
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
__decorate([
|
|
59
|
+
(0, decorators_1.Get)('/'),
|
|
60
|
+
__metadata("design:type", Function),
|
|
61
|
+
__metadata("design:paramtypes", []),
|
|
62
|
+
__metadata("design:returntype", void 0)
|
|
63
|
+
], UserController.prototype, "getUsers", null);
|
|
64
|
+
__decorate([
|
|
65
|
+
(0, decorators_1.Get)('/:id'),
|
|
66
|
+
__metadata("design:type", Function),
|
|
67
|
+
__metadata("design:paramtypes", []),
|
|
68
|
+
__metadata("design:returntype", void 0)
|
|
69
|
+
], UserController.prototype, "getUserById", null);
|
|
70
|
+
UserController = __decorate([
|
|
71
|
+
(0, decorators_1.Controller)('/api/users')
|
|
72
|
+
], UserController);
|
|
73
|
+
// Example usage of globalMiddlewares
|
|
74
|
+
async function startAppWithGlobalMiddlewares() {
|
|
75
|
+
const app = await (0, index_1.createBootifyApp)({
|
|
76
|
+
controllers: [UserController],
|
|
77
|
+
port: 3000,
|
|
78
|
+
enableSwagger: true,
|
|
79
|
+
// Global middlewares execute in the order they are defined
|
|
80
|
+
globalMiddlewares: [
|
|
81
|
+
corsMiddleware, // Executes first - handles CORS
|
|
82
|
+
authMiddleware, // Executes second - handles authentication
|
|
83
|
+
rateLimitMiddleware, // Executes third - handles rate limiting
|
|
84
|
+
loggingMiddleware // Executes fourth - handles custom logging
|
|
85
|
+
]
|
|
86
|
+
});
|
|
87
|
+
await app.start();
|
|
88
|
+
console.log('š Server started with global middlewares!');
|
|
89
|
+
console.log('š API Documentation: http://localhost:3000/api-docs');
|
|
90
|
+
console.log('š Test endpoint: http://localhost:3000/api/users');
|
|
91
|
+
}
|
|
92
|
+
// Uncomment to run this example
|
|
93
|
+
// startAppWithGlobalMiddlewares().catch(console.error)
|
|
94
|
+
//# sourceMappingURL=global-middleware-example.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"global-middleware-example.js","sourceRoot":"","sources":["../../src/examples/global-middleware-example.ts"],"names":[],"mappings":";;;;;;;;;;;AA8DA,sEAkBC;AAhFD,oCAA8D;AAC9D,mDAAoD;AAEpD,qCAAqC;AACrC,MAAM,cAAc,GAAsB,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,EAAE;IACjE,OAAO,CAAC,GAAG,CAAC,6BAA6B,CAAC,CAKzC;IAAC,OAAe,CAAC,IAAI,GAAG,EAAE,EAAE,EAAE,CAAC,EAAE,QAAQ,EAAE,UAAU,EAAE,CAAA;AAC1D,CAAC,CAAA;AAED,MAAM,mBAAmB,GAAsB,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,EAAE;IACtE,OAAO,CAAC,GAAG,CAAC,oCAAoC,CAAC,CAAA;IACjD,+BAA+B;IAC/B,0EAA0E;IAE1E,sCAAsC;IACtC,MAAM,QAAQ,GAAG,OAAO,CAAC,EAAE,CAAA;IAC3B,OAAO,CAAC,GAAG,CAAC,+BAA+B,QAAQ,EAAE,CAAC,CAAA;AACxD,CAAC,CAAA;AAED,MAAM,iBAAiB,GAAsB,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,EAAE;IACpE,OAAO,CAAC,GAAG,CAAC,uCAAuC,CAAC,CAAA;IACpD,gCAAgC;IAChC,8DAA8D;IAE9D,OAAO,CAAC,GAAG,CAAC,GAAG,OAAO,CAAC,MAAM,IAAI,OAAO,CAAC,GAAG,kBAAkB,OAAO,CAAC,OAAO,CAAC,YA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Q,2CAA2C;YACjE,mBAAmB,EAAG,yCAAyC;YAC/D,iBAAiB,CAAK,2CAA2C;SAClE;KACF,CAAC,CAAA;IAEF,MAAM,GAAG,CAAC,KAAK,EAAE,CAAA;IACjB,OAAO,CAAC,GAAG,CAAC,4CAA4C,CAAC,CAAA;IACzD,OAAO,CAAC,GAAG,CAAC,sDAAsD,CAAC,CAAA;IACnE,OAAO,CAAC,GAAG,CAAC,mDAAmD,CAAC,CAAA;AAClE,CAAC;AAED,gCAAgC;AAChC,uDAAuD"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/examples/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/examples/index.ts"],"names":[],"mappings":"AACA,OAAO,kBAAkB,CAAA"}
|
package/dist/examples/index.js
CHANGED
|
@@ -3,44 +3,100 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
require("reflect-metadata");
|
|
7
6
|
const dotenv_1 = __importDefault(require("dotenv"));
|
|
8
|
-
|
|
7
|
+
require("reflect-metadata");
|
|
9
8
|
const api_1 = require("../api");
|
|
9
|
+
const di_container_1 = require("../core/di-container");
|
|
10
|
+
const bootstrap_1 = require("../events/bootstrap");
|
|
10
11
|
const health_controller_1 = require("./controllers/health.controller");
|
|
11
12
|
const todo_controller_1 = require("./controllers/todo.controller");
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
const di_container_1 = require("../core/di-container");
|
|
15
|
-
const todo_service_1 = require("./services/todo.service");
|
|
13
|
+
dotenv_1.default.config();
|
|
14
|
+
// import { bootstrapCache } from '../cache/bootstrap'
|
|
16
15
|
const zod_1 = __importDefault(require("zod"));
|
|
17
|
-
const
|
|
18
|
-
// import { createBootifyApp } from './api'
|
|
19
|
-
// import { HealthController } from './examples/controllers/health.controller'
|
|
20
|
-
// import { TodoController } from './examples/controllers/todo.controller'
|
|
16
|
+
const basic_usage_1 = require("../auth/examples/basic-usage");
|
|
21
17
|
// --- Application Startup ---
|
|
18
|
+
const envSchema = zod_1.default.object({
|
|
19
|
+
NODE_ENV: zod_1.default.string().min(1),
|
|
20
|
+
JWT_SECRET: zod_1.default.string().min(1),
|
|
21
|
+
});
|
|
22
|
+
// Global middleware implementations
|
|
23
|
+
const corsMiddleware = async (request, reply) => {
|
|
24
|
+
console.log('š CORS middleware executed');
|
|
25
|
+
reply.header('Access-Control-Allow-Origin', '*');
|
|
26
|
+
reply.header('Access-Control-Allow-Methods', 'GET, POST, PUT, DELETE, OPTIONS');
|
|
27
|
+
reply.header('Access-Control-Allow-Headers', 'Content-Type, Authorization');
|
|
28
|
+
};
|
|
29
|
+
const requestTimingMiddleware = async (request, reply) => {
|
|
30
|
+
const startTime = Date.now();
|
|
31
|
+
console.log(`ā±ļø Request started: ${request.method} ${request.url}`);
|
|
32
|
+
request.startTime = startTime;
|
|
33
|
+
request.logTiming = () => {
|
|
34
|
+
const duration = Date.now() - startTime;
|
|
35
|
+
console.log(`ā±ļø Request completed in ${duration}ms: ${request.method} ${request.url}`);
|
|
36
|
+
};
|
|
37
|
+
};
|
|
38
|
+
const securityHeadersMiddleware = async (request, reply) => {
|
|
39
|
+
console.log('š Security headers middleware executed');
|
|
40
|
+
reply.header('X-Content-Type-Options', 'nosniff');
|
|
41
|
+
reply.header('X-Frame-Options', 'DENY');
|
|
42
|
+
reply.header('X-XSS-Protection', '1; mode=block');
|
|
43
|
+
reply.header('Strict-Transport-Security', 'max-age=31536000; includeSubDomains');
|
|
44
|
+
};
|
|
45
|
+
const requestLoggingMiddleware = async (request, reply) => {
|
|
46
|
+
const clientIP = request.ip;
|
|
47
|
+
const userAgent = request.headers['user-agent'] || 'Unknown';
|
|
48
|
+
console.log(`š Request: ${request.method} ${request.url} from ${clientIP} - ${userAgent}`);
|
|
49
|
+
};
|
|
22
50
|
async function main() {
|
|
23
51
|
// await intitializeLogging()
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
})
|
|
27
|
-
const allComponents = Array.from(
|
|
52
|
+
const { middleware: jwtAuthMiddleware, authManager } = await (0, basic_usage_1.setupJwtAuth)();
|
|
53
|
+
// Register authManager in DI container for controller injection
|
|
54
|
+
di_container_1.container.register('AuthManager', { useFactory: () => authManager });
|
|
55
|
+
const allComponents = Array.from(di_container_1.container.getRegisteredComponents());
|
|
28
56
|
await (0, bootstrap_1.bootstrapEventSystem)(allComponents);
|
|
29
57
|
// await bootstrapCache()
|
|
30
|
-
const { start } = await (0, api_1.createBootifyApp)({
|
|
58
|
+
const { app, start } = await (0, api_1.createBootifyApp)({
|
|
31
59
|
controllers: [health_controller_1.HealthController, todo_controller_1.TodoController],
|
|
32
60
|
enableSwagger: true,
|
|
33
|
-
port:
|
|
34
|
-
configSchema:
|
|
35
|
-
|
|
36
|
-
|
|
61
|
+
port: 8080,
|
|
62
|
+
configSchema: envSchema,
|
|
63
|
+
globalMiddlewares: [
|
|
64
|
+
jwtAuthMiddleware.authenticate({
|
|
65
|
+
strategies: ['jwt', 'api-key'],
|
|
66
|
+
skipPaths: ['/auth/login', '/auth/refresh', '/health']
|
|
67
|
+
}),
|
|
68
|
+
corsMiddleware, // 1st: Handle CORS headers
|
|
69
|
+
securityHeadersMiddleware, // 2nd: Add security headers
|
|
70
|
+
requestTimingMiddleware, // 3rd: Start request timing
|
|
71
|
+
requestLoggingMiddleware // 4th: Log request details
|
|
72
|
+
]
|
|
37
73
|
});
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
//
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
console.log(
|
|
74
|
+
await (0, basic_usage_1.registerJWTAuthRoutes)(app, authManager, jwtAuthMiddleware);
|
|
75
|
+
// Setup context middleware with authentication
|
|
76
|
+
// app.addHook('onRequest', createContextMiddleware(authContextExtractor));
|
|
77
|
+
// console.log('All components:', container.getRegisteredComponents())
|
|
78
|
+
// const animal = container.resolve<Animal>('Animal')
|
|
79
|
+
// // console.log(animal)
|
|
80
|
+
// const animalservice: AnimalService = container.resolve<AnimalService>(AnimalService)
|
|
81
|
+
// console.log(animalservice.animal === animalservice.animal1)
|
|
82
|
+
// console.log(animalservice.animal.name)
|
|
83
|
+
// console.log('š BootifyJS Example Server starting...');
|
|
84
|
+
// console.log('š§ Global middlewares enabled: CORS, Security Headers, Request Timing, Request Logging');
|
|
85
|
+
// console.log('š Available endpoints:');
|
|
86
|
+
// console.log(' GET /todos - List all todos (requires authentication)');
|
|
87
|
+
// console.log(' POST /todos - Create a new todo (requires authentication)');
|
|
88
|
+
// console.log(' GET /todos/:id - Get a specific todo (requires authentication)');
|
|
89
|
+
// console.log(' PUT /todos/:id - Update a todo (requires authentication)');
|
|
90
|
+
// console.log(' DELETE /todos/:id - Delete a todo (requires authentication)');
|
|
91
|
+
// console.log(' GET /animals - List all animals');
|
|
92
|
+
// console.log(' POST /animals - Create a new animal');
|
|
93
|
+
// console.log('š Authentication endpoints:');
|
|
94
|
+
// console.log(' POST /auth/login - Login to get JWT token');
|
|
95
|
+
// console.log(' GET /auth/info - Check authentication status');
|
|
96
|
+
// console.log('š” Use @UseMiddleware(authenticate()) decorator for protected routes!');
|
|
97
|
+
// console.log('š Test credentials: admin/admin123, manager/manager123, user/user123');
|
|
98
|
+
// console.log('š CORS enabled for all origins');
|
|
99
|
+
// console.log('š Security headers automatically added to all responses');
|
|
44
100
|
await start();
|
|
45
101
|
}
|
|
46
102
|
main();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/examples/index.ts"],"names":[],"mappings":";;;;;AAAA,4BAAyB;AACzB,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/examples/index.ts"],"names":[],"mappings":";;;;;AAAA,oDAA2B;AAC3B,4BAAyB;AACzB,gCAAyC;AAE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EAAE,CAAC,oCAAgB,EAAE,gCAAc,CAAC;QAC/C,aAAa,EAAE,IAAI;QACnB,IAAI,EAAE,IAAI;QACV,YAAY,EAAE,SAAS;QACvB,iBAAiB,EAAE;YACjB,iBAAiB,CAAC,YAAY,CAAC;gBAC7B,UAAU,EAAE,CAAC,KAAK,EAAE,SAAS,CAAC;gBAC9B,SAAS,EAAE,CAAC,aAAa,EAAE,eAAe,EAAE,SAAS,CAAC;aACvD,CAAC;YACF,cAAc,EAAe,2BAA2B;YACxD,yBAAyB,EAAI,4BAA4B;YACzD,uBAAuB,EAAM,4BAA4B;YACzD,wBAAwB,CAAK,2BAA2B;SACzD;KACF,CAAC,CAAA;IAEF,MAAM,IAAA,mCAAqB,EAAC,GAAG,EAAE,WAAW,EAAE,iBAAiB,CAAC,CAAA;IAEhE,+CAA+C;IAC/C,2EAA2E;IAE3E,sEAAsE;IACtE,qDAAqD;IAErD,2BAA2B;IAC3B,uFAAuF;IACvF,8DAA8D;IAC9D,yCAAyC;IAEzC,0DAA0D;IAC1D,yGAAyG;IACzG,0CAA0C;IAC1C,0EAA0E;IAC1E,8EAA8E;IAC9E,mFAAmF;IACnF,6EAA6E;IAC7E,gFAAgF;IAChF,oDAAoD;IACpD,wDAAwD;IACxD,+CAA+C;IAC/C,8DAA8D;IAC9D,iEAAiE;IACjE,wFAAwF;IACxF,wFAAwF;IACxF,kDAAkD;IAClD,2EAA2E;IAE3E,MAAM,KAAK,EAAE,CAAA;AACf,CAAC;AAED,IAAI,EAAE,CAAA"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { FastifyInstance } from 'fastify';
|
|
2
|
+
/**
|
|
3
|
+
* JWT Authentication Example
|
|
4
|
+
* Demonstrates how to set up JWT authentication with global middleware
|
|
5
|
+
* and protected routes in a Fastify application
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Protected User Controller
|
|
9
|
+
* Example controller that requires authentication
|
|
10
|
+
*/
|
|
11
|
+
declare class ProtectedUserController {
|
|
12
|
+
/**
|
|
13
|
+
* Get current user profile (requires authentication)
|
|
14
|
+
*/
|
|
15
|
+
getProfile(request: any, reply: any): Promise<void>;
|
|
16
|
+
/**
|
|
17
|
+
* Update user profile (requires authentication)
|
|
18
|
+
*/
|
|
19
|
+
updateProfile(request: any, reply: any): Promise<void>;
|
|
20
|
+
/**
|
|
21
|
+
* Admin only endpoint (requires admin role)
|
|
22
|
+
*/
|
|
23
|
+
getAllUsers(request: any, reply: any): Promise<void>;
|
|
24
|
+
/**
|
|
25
|
+
* Delete user (requires admin permission)
|
|
26
|
+
*/
|
|
27
|
+
deleteUser(request: any, reply: any): Promise<void>;
|
|
28
|
+
/**
|
|
29
|
+
* Public endpoint (optional authentication)
|
|
30
|
+
*/
|
|
31
|
+
getPublicInfo(request: any, reply: any): Promise<void>;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Setup JWT Authentication Routes and Middleware
|
|
35
|
+
*/
|
|
36
|
+
export declare function setupJwtAuth(fastify: FastifyInstance): Promise<void>;
|
|
37
|
+
/**
|
|
38
|
+
* Setup Global JWT Authentication Middleware
|
|
39
|
+
* This applies JWT authentication to ALL routes except those explicitly excluded
|
|
40
|
+
*/
|
|
41
|
+
export declare function setupGlobalJwtAuth(fastify: FastifyInstance): Promise<void>;
|
|
42
|
+
/**
|
|
43
|
+
* Start Fastify server with JWT authentication
|
|
44
|
+
*/
|
|
45
|
+
export declare function startAppWithJwtAuth(useGlobalAuth?: boolean): Promise<void>;
|
|
46
|
+
export { ProtectedUserController };
|
|
47
|
+
//# sourceMappingURL=jwt-auth-example.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"jwt-auth-example.d.ts","sourceRoot":"","sources":["../../src/examples/jwt-auth-example.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAK1C;;;;GAIG;AAEH;;;GAGG;AACH,cAAM,uBAAuB;IAC3B;;OAEG;IACG,UAAU,CAAC,OAAO,EAAE,GAAG,EAAE,KAAK,EAAE,GAAG;IAUzC;;OAEG;IACG,aAAa,CAAC,OAAO,EAAE,GAAG,EAAE,KAAK,EAAE,GAAG;IAyB5C;;OAEG;IACG,WAAW,CAAC,OAAO,EAAE,GAAG,EAAE,KAAK,EAAE,GAAG;IAU1C;;OAEG;IACG,UAAU,CAAC,OAAO,EAAE,GAAG,EAAE,KAAK,EAAE,GAAG;IAkBzC;;OAEG;IACG,aAAa,CAAC,OAAO,EAAE,GAAG,EAAE,KAAK,EAAE,GAAG;CAc7C;AAED;;GAEG;AACH,wBAAsB,YAAY,CAAC,OAAO,EAAE,eAAe,iBAmE1D;AAED;;;GAGG;AACH,wBAAsB,kBAAkB,CAAC,OAAO,EAAE,eAAe,iBA2EhE;AAED;;GAEG;AACH,wBAAsB,mBAAmB,CAAC,aAAa,GAAE,OAAe,iBAgFvE;AAGD,OAAO,EAAE,uBAAuB,EAAE,CAAC"}
|
|
@@ -0,0 +1,316 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ProtectedUserController = void 0;
|
|
4
|
+
exports.setupJwtAuth = setupJwtAuth;
|
|
5
|
+
exports.setupGlobalJwtAuth = setupGlobalJwtAuth;
|
|
6
|
+
exports.startAppWithJwtAuth = startAppWithJwtAuth;
|
|
7
|
+
const auth_controller_1 = require("./controllers/auth.controller");
|
|
8
|
+
const auth_middleware_1 = require("./auth/auth.middleware");
|
|
9
|
+
const user_service_1 = require("./services/user.service");
|
|
10
|
+
/**
|
|
11
|
+
* JWT Authentication Example
|
|
12
|
+
* Demonstrates how to set up JWT authentication with global middleware
|
|
13
|
+
* and protected routes in a Fastify application
|
|
14
|
+
*/
|
|
15
|
+
/**
|
|
16
|
+
* Protected User Controller
|
|
17
|
+
* Example controller that requires authentication
|
|
18
|
+
*/
|
|
19
|
+
class ProtectedUserController {
|
|
20
|
+
/**
|
|
21
|
+
* Get current user profile (requires authentication)
|
|
22
|
+
*/
|
|
23
|
+
async getProfile(request, reply) {
|
|
24
|
+
const user = request.user;
|
|
25
|
+
const profile = await user_service_1.userService.getUserProfile(user.id);
|
|
26
|
+
reply.send({
|
|
27
|
+
success: true,
|
|
28
|
+
data: profile
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Update user profile (requires authentication)
|
|
33
|
+
*/
|
|
34
|
+
async updateProfile(request, reply) {
|
|
35
|
+
const user = request.user;
|
|
36
|
+
const { email, firstName, lastName } = request.body;
|
|
37
|
+
const updatedUser = await user_service_1.userService.updateProfile(user.id, {
|
|
38
|
+
email,
|
|
39
|
+
firstName,
|
|
40
|
+
lastName
|
|
41
|
+
});
|
|
42
|
+
if (!updatedUser) {
|
|
43
|
+
reply.code(404).send({
|
|
44
|
+
error: 'USER_NOT_FOUND',
|
|
45
|
+
message: 'User not found'
|
|
46
|
+
});
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
reply.send({
|
|
50
|
+
success: true,
|
|
51
|
+
data: updatedUser,
|
|
52
|
+
message: 'Profile updated successfully'
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Admin only endpoint (requires admin role)
|
|
57
|
+
*/
|
|
58
|
+
async getAllUsers(request, reply) {
|
|
59
|
+
const users = await user_service_1.userService.userRepository.findAll();
|
|
60
|
+
reply.send({
|
|
61
|
+
success: true,
|
|
62
|
+
data: users,
|
|
63
|
+
count: users.length
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Delete user (requires admin permission)
|
|
68
|
+
*/
|
|
69
|
+
async deleteUser(request, reply) {
|
|
70
|
+
const { userId } = request.params;
|
|
71
|
+
const success = await user_service_1.userService.userRepository.delete(userId);
|
|
72
|
+
if (!success) {
|
|
73
|
+
reply.code(404).send({
|
|
74
|
+
error: 'USER_NOT_FOUND',
|
|
75
|
+
message: 'User not found'
|
|
76
|
+
});
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
reply.send({
|
|
80
|
+
success: true,
|
|
81
|
+
message: 'User deleted successfully'
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Public endpoint (optional authentication)
|
|
86
|
+
*/
|
|
87
|
+
async getPublicInfo(request, reply) {
|
|
88
|
+
const isAuthenticated = request.isAuthenticated;
|
|
89
|
+
const user = request.user;
|
|
90
|
+
reply.send({
|
|
91
|
+
success: true,
|
|
92
|
+
data: {
|
|
93
|
+
message: 'This is public information',
|
|
94
|
+
timestamp: new Date().toISOString(),
|
|
95
|
+
authenticated: isAuthenticated,
|
|
96
|
+
user: isAuthenticated ? { id: user.id, username: user.username } : null
|
|
97
|
+
}
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
exports.ProtectedUserController = ProtectedUserController;
|
|
102
|
+
/**
|
|
103
|
+
* Setup JWT Authentication Routes and Middleware
|
|
104
|
+
*/
|
|
105
|
+
async function setupJwtAuth(fastify) {
|
|
106
|
+
// Initialize controllers
|
|
107
|
+
const authController = new auth_controller_1.AuthController();
|
|
108
|
+
const userController = new ProtectedUserController();
|
|
109
|
+
// Register authentication routes (no middleware needed)
|
|
110
|
+
fastify.register(async function authRoutes(fastify) {
|
|
111
|
+
fastify.post('/auth/login', async (request, reply) => {
|
|
112
|
+
return authController.login(request.body);
|
|
113
|
+
});
|
|
114
|
+
fastify.post('/auth/refresh', async (request, reply) => {
|
|
115
|
+
return authController.refreshToken(request.body);
|
|
116
|
+
});
|
|
117
|
+
fastify.post('/auth/logout', async (request, reply) => {
|
|
118
|
+
return authController.logout(request.body);
|
|
119
|
+
});
|
|
120
|
+
fastify.get('/auth/info', async (request, reply) => {
|
|
121
|
+
return authController.getAuthInfo();
|
|
122
|
+
});
|
|
123
|
+
});
|
|
124
|
+
// Register public routes with optional authentication
|
|
125
|
+
fastify.register(async function publicRoutes(fastify) {
|
|
126
|
+
// Add optional auth middleware
|
|
127
|
+
fastify.addHook('preHandler', auth_middleware_1.optionalJwtAuthMiddleware);
|
|
128
|
+
fastify.get('/public/info', async (request, reply) => {
|
|
129
|
+
return userController.getPublicInfo(request, reply);
|
|
130
|
+
});
|
|
131
|
+
});
|
|
132
|
+
// Register protected user routes (requires authentication)
|
|
133
|
+
fastify.register(async function protectedRoutes(fastify) {
|
|
134
|
+
// Add JWT authentication middleware to all routes in this group
|
|
135
|
+
fastify.addHook('preHandler', auth_middleware_1.jwtAuthMiddleware);
|
|
136
|
+
fastify.get('/user/profile', async (request, reply) => {
|
|
137
|
+
return userController.getProfile(request, reply);
|
|
138
|
+
});
|
|
139
|
+
fastify.put('/user/profile', async (request, reply) => {
|
|
140
|
+
return userController.updateProfile(request, reply);
|
|
141
|
+
});
|
|
142
|
+
});
|
|
143
|
+
// Register admin routes (requires admin role)
|
|
144
|
+
fastify.register(async function adminRoutes(fastify) {
|
|
145
|
+
// Add JWT authentication middleware
|
|
146
|
+
fastify.addHook('preHandler', auth_middleware_1.jwtAuthMiddleware);
|
|
147
|
+
// Add role-based authorization middleware
|
|
148
|
+
fastify.addHook('preHandler', (0, auth_middleware_1.requireRoles)(['admin']));
|
|
149
|
+
fastify.get('/admin/users', async (request, reply) => {
|
|
150
|
+
return userController.getAllUsers(request, reply);
|
|
151
|
+
});
|
|
152
|
+
});
|
|
153
|
+
// Register admin routes with permission-based access
|
|
154
|
+
fastify.register(async function adminPermissionRoutes(fastify) {
|
|
155
|
+
// Add JWT authentication middleware
|
|
156
|
+
fastify.addHook('preHandler', auth_middleware_1.jwtAuthMiddleware);
|
|
157
|
+
// Add permission-based authorization middleware
|
|
158
|
+
fastify.addHook('preHandler', (0, auth_middleware_1.requirePermissions)(['delete']));
|
|
159
|
+
fastify.delete('/admin/users/:userId', async (request, reply) => {
|
|
160
|
+
return userController.deleteUser(request, reply);
|
|
161
|
+
});
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* Setup Global JWT Authentication Middleware
|
|
166
|
+
* This applies JWT authentication to ALL routes except those explicitly excluded
|
|
167
|
+
*/
|
|
168
|
+
async function setupGlobalJwtAuth(fastify) {
|
|
169
|
+
// Define paths that should skip authentication
|
|
170
|
+
const skipAuthPaths = [
|
|
171
|
+
'/auth/login',
|
|
172
|
+
'/auth/refresh',
|
|
173
|
+
'/public/info',
|
|
174
|
+
'/health',
|
|
175
|
+
'/docs',
|
|
176
|
+
'/docs/static/*'
|
|
177
|
+
];
|
|
178
|
+
// Global authentication middleware
|
|
179
|
+
fastify.addHook('preHandler', async (request, reply) => {
|
|
180
|
+
// Skip authentication for excluded paths
|
|
181
|
+
const shouldSkip = skipAuthPaths.some(path => {
|
|
182
|
+
if (path.endsWith('/*')) {
|
|
183
|
+
const basePath = path.slice(0, -2);
|
|
184
|
+
return request.url.startsWith(basePath);
|
|
185
|
+
}
|
|
186
|
+
return request.url === path || request.url.startsWith(path + '?');
|
|
187
|
+
});
|
|
188
|
+
if (shouldSkip) {
|
|
189
|
+
return;
|
|
190
|
+
}
|
|
191
|
+
// Apply JWT authentication middleware
|
|
192
|
+
await (0, auth_middleware_1.jwtAuthMiddleware)(request, reply);
|
|
193
|
+
});
|
|
194
|
+
// Initialize controllers
|
|
195
|
+
const authController = new auth_controller_1.AuthController();
|
|
196
|
+
const userController = new ProtectedUserController();
|
|
197
|
+
// Register all routes (authentication will be handled globally)
|
|
198
|
+
fastify.post('/auth/login', async (request, reply) => {
|
|
199
|
+
return authController.login(request.body);
|
|
200
|
+
});
|
|
201
|
+
fastify.post('/auth/refresh', async (request, reply) => {
|
|
202
|
+
return authController.refreshToken(request.body);
|
|
203
|
+
});
|
|
204
|
+
fastify.post('/auth/logout', async (request, reply) => {
|
|
205
|
+
return authController.logout(request.body);
|
|
206
|
+
});
|
|
207
|
+
fastify.get('/auth/info', async (request, reply) => {
|
|
208
|
+
return authController.getAuthInfo();
|
|
209
|
+
});
|
|
210
|
+
// Public routes
|
|
211
|
+
fastify.get('/public/info', async (request, reply) => {
|
|
212
|
+
return userController.getPublicInfo(request, reply);
|
|
213
|
+
});
|
|
214
|
+
// Protected routes (will be automatically protected by global middleware)
|
|
215
|
+
fastify.get('/user/profile', async (request, reply) => {
|
|
216
|
+
return userController.getProfile(request, reply);
|
|
217
|
+
});
|
|
218
|
+
fastify.put('/user/profile', async (request, reply) => {
|
|
219
|
+
return userController.updateProfile(request, reply);
|
|
220
|
+
});
|
|
221
|
+
// Admin routes with additional role checks
|
|
222
|
+
fastify.register(async function adminRoutes(fastify) {
|
|
223
|
+
fastify.addHook('preHandler', (0, auth_middleware_1.requireRoles)(['admin']));
|
|
224
|
+
fastify.get('/admin/users', async (request, reply) => {
|
|
225
|
+
return userController.getAllUsers(request, reply);
|
|
226
|
+
});
|
|
227
|
+
});
|
|
228
|
+
fastify.register(async function adminPermissionRoutes(fastify) {
|
|
229
|
+
fastify.addHook('preHandler', (0, auth_middleware_1.requirePermissions)(['delete']));
|
|
230
|
+
fastify.delete('/admin/users/:userId', async (request, reply) => {
|
|
231
|
+
return userController.deleteUser(request, reply);
|
|
232
|
+
});
|
|
233
|
+
});
|
|
234
|
+
}
|
|
235
|
+
/**
|
|
236
|
+
* Start Fastify server with JWT authentication
|
|
237
|
+
*/
|
|
238
|
+
async function startAppWithJwtAuth(useGlobalAuth = false) {
|
|
239
|
+
const fastify = require('fastify')({ logger: true });
|
|
240
|
+
try {
|
|
241
|
+
// Setup CORS
|
|
242
|
+
await fastify.register(require('@fastify/cors'), {
|
|
243
|
+
origin: true,
|
|
244
|
+
credentials: true
|
|
245
|
+
});
|
|
246
|
+
// Setup JSON schema validation
|
|
247
|
+
fastify.setErrorHandler((error, request, reply) => {
|
|
248
|
+
if (error.validation) {
|
|
249
|
+
reply.code(400).send({
|
|
250
|
+
error: 'VALIDATION_ERROR',
|
|
251
|
+
message: 'Request validation failed',
|
|
252
|
+
details: error.validation
|
|
253
|
+
});
|
|
254
|
+
return;
|
|
255
|
+
}
|
|
256
|
+
if (error.statusCode) {
|
|
257
|
+
reply.code(error.statusCode).send({
|
|
258
|
+
error: error.name || 'ERROR',
|
|
259
|
+
message: error.message
|
|
260
|
+
});
|
|
261
|
+
return;
|
|
262
|
+
}
|
|
263
|
+
reply.code(500).send({
|
|
264
|
+
error: 'INTERNAL_SERVER_ERROR',
|
|
265
|
+
message: 'An unexpected error occurred'
|
|
266
|
+
});
|
|
267
|
+
});
|
|
268
|
+
// Setup authentication
|
|
269
|
+
if (useGlobalAuth) {
|
|
270
|
+
console.log('Setting up global JWT authentication...');
|
|
271
|
+
await setupGlobalJwtAuth(fastify);
|
|
272
|
+
}
|
|
273
|
+
else {
|
|
274
|
+
console.log('Setting up route-specific JWT authentication...');
|
|
275
|
+
await setupJwtAuth(fastify);
|
|
276
|
+
}
|
|
277
|
+
// Health check endpoint
|
|
278
|
+
fastify.get('/health', async (request, reply) => {
|
|
279
|
+
return {
|
|
280
|
+
status: 'ok',
|
|
281
|
+
timestamp: new Date().toISOString(),
|
|
282
|
+
uptime: process.uptime()
|
|
283
|
+
};
|
|
284
|
+
});
|
|
285
|
+
// Start server
|
|
286
|
+
const port = process.env.PORT || 3000;
|
|
287
|
+
const host = process.env.HOST || '0.0.0.0';
|
|
288
|
+
await fastify.listen({ port: Number(port), host });
|
|
289
|
+
console.log(`\nš Server running at http://${host}:${port}`);
|
|
290
|
+
console.log('\nš Available endpoints:');
|
|
291
|
+
console.log(' POST /auth/login - Login with username/password');
|
|
292
|
+
console.log(' POST /auth/refresh - Refresh access token');
|
|
293
|
+
console.log(' POST /auth/logout - Logout and revoke tokens');
|
|
294
|
+
console.log(' GET /auth/info - Get current user info (requires auth)');
|
|
295
|
+
console.log(' GET /public/info - Public endpoint (optional auth)');
|
|
296
|
+
console.log(' GET /user/profile - Get user profile (requires auth)');
|
|
297
|
+
console.log(' PUT /user/profile - Update user profile (requires auth)');
|
|
298
|
+
console.log(' GET /admin/users - Get all users (requires admin role)');
|
|
299
|
+
console.log(' DELETE /admin/users/:userId - Delete user (requires delete permission)');
|
|
300
|
+
console.log(' GET /health - Health check');
|
|
301
|
+
console.log('\nš Test credentials:');
|
|
302
|
+
console.log(' Admin: username=admin, password=admin123');
|
|
303
|
+
console.log(' User: username=user, password=user123');
|
|
304
|
+
console.log(' Guest: username=guest, password=guest123');
|
|
305
|
+
}
|
|
306
|
+
catch (err) {
|
|
307
|
+
console.error('Error starting server:', err);
|
|
308
|
+
process.exit(1);
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
// If this file is run directly, start the server
|
|
312
|
+
if (require.main === module) {
|
|
313
|
+
const useGlobalAuth = process.argv.includes('--global');
|
|
314
|
+
startAppWithJwtAuth(useGlobalAuth);
|
|
315
|
+
}
|
|
316
|
+
//# sourceMappingURL=jwt-auth-example.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"jwt-auth-example.js","sourceRoot":"","sources":["../../src/examples/jwt-auth-example.ts"],"names":[],"mappings":";;;AAiHA,oCAmEC;AAMD,gDA2EC;AAKD,kDAgFC;AAzVD,mEAA+D;AAC/D,4DAAwH;AACxH,0DAAsD;AAEtD;;;;GAIG;AAEH;;;GAGG;AACH,MAAM,uBAAuB;IAC3B;;OAEG;IACH,KAAK,CAAC,UAAU,CAAC,OAAY,EAAE,KAAU;QACvC,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC;QAC1B,MAAM,OAAO,GAAG,MAAM,0BAAW,CAAC,cAAc,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;QAE1D,KAAK,CAAC,IAAI,CAAC;YACT,OAAO,EAAE,IAAI;YACb,IAAI,EAAE,OAAO;SACd,CAAC,CAAC;IACL,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,aAAa,CAAC,OAAY,EAAE,KAAU;QAC1C,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC;QAC1B,MAAM,EAAE,KAAK,EAAE,SAAS,EAAE,QAAQ,EAAE,GAAG,OAAO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