@kozojs/cli 0.1.17 → 0.1.19

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.
Files changed (2) hide show
  1. package/lib/index.js +10 -16
  2. 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
- const { port } = await app.nativeListen(PORT);
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');
@@ -1495,24 +1492,21 @@ ${auth ? "JWT_SECRET=change-me-to-a-random-secret-at-least-32-chars\n" : ""}`;
1495
1492
  exclude: ["node_modules", "dist"]
1496
1493
  };
1497
1494
  await import_fs_extra.default.writeJSON(import_node_path.default.join(apiDir, "tsconfig.json"), tsconfig, { spaces: 2 });
1498
- const dbImport = hasDb ? `import { createDb } from './db/index.js';
1499
- ` : "";
1500
1495
  const authImport = auth ? `import { authenticateJWT } from '@kozojs/auth';
1501
1496
  ` : "";
1502
- const servicesSetup = hasDb ? `
1503
- const db = await createDb();
1504
- const services = { db };
1505
- ` : "\nconst services = {};\n";
1497
+ const servicesSetup = "\nconst services = {};\n";
1506
1498
  const authMiddleware = auth ? `
1507
- // Protect resource routes with JWT (auth login route remains public)
1499
+ // JWT protects all /api/* routes except /api/auth/*
1508
1500
  const JWT_SECRET = process.env.JWT_SECRET || 'change-me';
1509
- app.use('*', authenticateJWT(JWT_SECRET, { prefix: '/api/users' }));
1510
- app.use('*', authenticateJWT(JWT_SECRET, { prefix: '/api/posts' }));
1511
- app.use('*', authenticateJWT(JWT_SECRET, { prefix: '/api/tasks' }));
1501
+ const _jwt = authenticateJWT(JWT_SECRET, { prefix: '' });
1502
+ app.getApp().use('/api/*', (c, next) => {
1503
+ if (c.req.path.startsWith('/api/auth/')) return next();
1504
+ return _jwt(c, next);
1505
+ });
1512
1506
  ` : "";
1513
1507
  await import_fs_extra.default.writeFile(import_node_path.default.join(apiDir, "src", "index.ts"), `import 'dotenv/config';
1514
1508
  import { createKozo } from '@kozojs/core';
1515
- ${dbImport}${authImport}import { registerRoutes } from './routes/index.js';
1509
+ ${authImport}import { registerRoutes } from './routes/index.js';
1516
1510
  ${servicesSetup}
1517
1511
  const app = createKozo({ port: 3000, services });
1518
1512
  ${authMiddleware}
@@ -1522,7 +1516,7 @@ export type AppType = typeof app;
1522
1516
 
1523
1517
  console.log('\u{1F525} ${projectName} API starting on http://localhost:3000');
1524
1518
  console.log('\u{1F4DA} Endpoints: /api/health, /api/users, /api/posts, /api/tasks, /api/stats');
1525
- await app.nativeListen();
1519
+ await app.listen();
1526
1520
  `);
1527
1521
  await import_fs_extra.default.writeFile(import_node_path.default.join(apiDir, "src", "data", "index.ts"), `import { z } from 'zod';
1528
1522
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kozojs/cli",
3
- "version": "0.1.17",
3
+ "version": "0.1.19",
4
4
  "description": "CLI to scaffold new Kozo Framework projects - The next-gen TypeScript Backend Framework",
5
5
  "bin": {
6
6
  "create-kozo": "./lib/index.js",