@kozojs/cli 0.1.18 → 0.1.20
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/lib/index.js +9 -9
- package/package.json +1 -1
package/lib/index.js
CHANGED
|
@@ -574,12 +574,9 @@ process.on('SIGINT', () => shutdown.shutdown());
|
|
|
574
574
|
// \u2500\u2500\u2500 Start \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500
|
|
575
575
|
console.log('');
|
|
576
576
|
console.log('\u{1F525} Kozo server starting\u2026');
|
|
577
|
-
console.log('\u26A1 Powered by uWebSockets.js (native per-route C++ matching)');
|
|
578
577
|
console.log('');
|
|
579
578
|
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
console.log(\`\u{1F680} Listening on http://localhost:\${port}\`);
|
|
579
|
+
await app.listen(PORT);
|
|
583
580
|
console.log('');
|
|
584
581
|
console.log('\u{1F4DA} Endpoints:');
|
|
585
582
|
console.log(' GET /health Health check');
|
|
@@ -1499,11 +1496,14 @@ ${auth ? "JWT_SECRET=change-me-to-a-random-secret-at-least-32-chars\n" : ""}`;
|
|
|
1499
1496
|
` : "";
|
|
1500
1497
|
const servicesSetup = "\nconst services = {};\n";
|
|
1501
1498
|
const authMiddleware = auth ? `
|
|
1502
|
-
//
|
|
1499
|
+
// JWT protects all /api/* routes except public ones
|
|
1503
1500
|
const JWT_SECRET = process.env.JWT_SECRET || 'change-me';
|
|
1504
|
-
|
|
1505
|
-
|
|
1506
|
-
app.use('
|
|
1501
|
+
const _jwt = authenticateJWT(JWT_SECRET, { prefix: '' });
|
|
1502
|
+
const publicPaths = ['/api/auth/', '/api/health', '/api/stats'];
|
|
1503
|
+
app.getApp().use('/api/*', (c, next) => {
|
|
1504
|
+
if (publicPaths.some(p => c.req.path.startsWith(p))) return next();
|
|
1505
|
+
return _jwt(c, next);
|
|
1506
|
+
});
|
|
1507
1507
|
` : "";
|
|
1508
1508
|
await import_fs_extra.default.writeFile(import_node_path.default.join(apiDir, "src", "index.ts"), `import 'dotenv/config';
|
|
1509
1509
|
import { createKozo } from '@kozojs/core';
|
|
@@ -1517,7 +1517,7 @@ export type AppType = typeof app;
|
|
|
1517
1517
|
|
|
1518
1518
|
console.log('\u{1F525} ${projectName} API starting on http://localhost:3000');
|
|
1519
1519
|
console.log('\u{1F4DA} Endpoints: /api/health, /api/users, /api/posts, /api/tasks, /api/stats');
|
|
1520
|
-
await app.
|
|
1520
|
+
await app.listen();
|
|
1521
1521
|
`);
|
|
1522
1522
|
await import_fs_extra.default.writeFile(import_node_path.default.join(apiDir, "src", "data", "index.ts"), `import { z } from 'zod';
|
|
1523
1523
|
|