@kuckit/app-server 2.0.7 → 3.0.2
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/index.d.ts +3 -0
- package/dist/index.js +15 -4
- package/package.json +7 -7
package/dist/index.d.ts
CHANGED
|
@@ -164,6 +164,8 @@ interface SetupRoutesOptions {
|
|
|
164
164
|
name: string;
|
|
165
165
|
router: express.Router;
|
|
166
166
|
basePath: string;
|
|
167
|
+
bodyParser: 'json' | 'raw' | 'none';
|
|
168
|
+
useSession: boolean;
|
|
167
169
|
}>;
|
|
168
170
|
}
|
|
169
171
|
/**
|
|
@@ -185,6 +187,7 @@ declare const setupModuleRestRouters: (app: Express, options: SetupRoutesOptions
|
|
|
185
187
|
/**
|
|
186
188
|
* Setup health check endpoint (includes database connectivity check)
|
|
187
189
|
* Used for liveness probes and ongoing health monitoring.
|
|
190
|
+
* Also provides a root / endpoint for basic server availability.
|
|
188
191
|
*/
|
|
189
192
|
declare const setupHealth: (app: Express, container: KuckitContainer) => void;
|
|
190
193
|
/**
|
package/dist/index.js
CHANGED
|
@@ -121,9 +121,13 @@ const setupAPIReference = (app, options) => {
|
|
|
121
121
|
const setupModuleRestRouters = (app, options) => {
|
|
122
122
|
const routers = options.restRouters ?? [];
|
|
123
123
|
const sessionMiddleware = createSessionMiddleware();
|
|
124
|
-
for (const { name, router, basePath } of routers) {
|
|
125
|
-
|
|
126
|
-
|
|
124
|
+
for (const { name, router, basePath, bodyParser, useSession } of routers) {
|
|
125
|
+
const middlewares = [];
|
|
126
|
+
if (bodyParser === "json") middlewares.push(express.json());
|
|
127
|
+
else if (bodyParser === "raw") middlewares.push(express.raw({ type: "application/json" }));
|
|
128
|
+
if (useSession) middlewares.push(sessionMiddleware);
|
|
129
|
+
app.use(`/api${basePath}`, ...middlewares, router);
|
|
130
|
+
console.log(`[REST] Mounted module router: /api${basePath} (${name}) [bodyParser=${bodyParser}, auth=${useSession}]`);
|
|
127
131
|
}
|
|
128
132
|
};
|
|
129
133
|
/**
|
|
@@ -141,8 +145,12 @@ const setupStartup = (app) => {
|
|
|
141
145
|
/**
|
|
142
146
|
* Setup health check endpoint (includes database connectivity check)
|
|
143
147
|
* Used for liveness probes and ongoing health monitoring.
|
|
148
|
+
* Also provides a root / endpoint for basic server availability.
|
|
144
149
|
*/
|
|
145
150
|
const setupHealth = (app, container) => {
|
|
151
|
+
app.get("/", (_req, res) => {
|
|
152
|
+
res.json({ status: "ok" });
|
|
153
|
+
});
|
|
146
154
|
app.get("/health", async (_req, res) => {
|
|
147
155
|
const { dbPool } = container.cradle;
|
|
148
156
|
try {
|
|
@@ -236,10 +244,13 @@ const buildContainer = async (options) => {
|
|
|
236
244
|
rpcRouter[reg.name] = reg.router;
|
|
237
245
|
} else if (reg.type === "rest-router") {
|
|
238
246
|
const basePath = reg.prefix ?? `/${reg.name}`;
|
|
247
|
+
const opts = reg.options ?? {};
|
|
239
248
|
restRouters.push({
|
|
240
249
|
name: reg.name,
|
|
241
250
|
router: reg.router,
|
|
242
|
-
basePath
|
|
251
|
+
basePath,
|
|
252
|
+
bodyParser: opts.bodyParser ?? "json",
|
|
253
|
+
useSession: !(opts.skipAuth ?? false)
|
|
243
254
|
});
|
|
244
255
|
}
|
|
245
256
|
container.resolve("logger").info(`Loaded ${registrations.length} API registrations from modules`);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kuckit/app-server",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.2",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -23,12 +23,12 @@
|
|
|
23
23
|
"prepublishOnly": "npm run build && node ../../scripts/resolve-workspace-protocols.cjs && node ../../scripts/check-no-workspace-protocol.cjs"
|
|
24
24
|
},
|
|
25
25
|
"dependencies": {
|
|
26
|
-
"@kuckit/sdk": "^
|
|
27
|
-
"@kuckit/api": "^
|
|
28
|
-
"@kuckit/db": "^
|
|
29
|
-
"@kuckit/domain": "^
|
|
30
|
-
"@kuckit/infrastructure": "^
|
|
31
|
-
"@kuckit/auth": "^
|
|
26
|
+
"@kuckit/sdk": "^3.0.2",
|
|
27
|
+
"@kuckit/api": "^3.0.2",
|
|
28
|
+
"@kuckit/db": "^3.0.2",
|
|
29
|
+
"@kuckit/domain": "^3.0.2",
|
|
30
|
+
"@kuckit/infrastructure": "^3.0.2",
|
|
31
|
+
"@kuckit/auth": "^3.0.2",
|
|
32
32
|
"express": "^5.1.0",
|
|
33
33
|
"cors": "^2.8.5",
|
|
34
34
|
"awilix": "^12.0.5",
|