@seip/bluebird-js 0.0.1 → 0.1.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.
Files changed (81) hide show
  1. package/.env_example +53 -53
  2. package/AGENTS.md +426 -403
  3. package/LICENSE +1 -1
  4. package/README.md +292 -285
  5. package/app/routes/api.js +50 -50
  6. package/app/routes/web.js +55 -53
  7. package/app/views/about.js +63 -0
  8. package/app/views/dashboard.js +147 -0
  9. package/app/views/index.js +80 -0
  10. package/app/views/layouts/main/view.js +81 -0
  11. package/app/views/legal/terms.html +19 -0
  12. package/app/views/login.js +80 -0
  13. package/core/app.d.ts +18 -18
  14. package/core/app.js +684 -644
  15. package/core/auth.d.ts +13 -13
  16. package/core/auth.js +326 -326
  17. package/core/cache.d.ts +17 -17
  18. package/core/cache.js +475 -475
  19. package/core/cli/doctor.js +287 -287
  20. package/core/cli/ecosystem.js +162 -162
  21. package/core/cli/init.js +779 -779
  22. package/core/cli/migrate.js +541 -541
  23. package/core/cli/model.js +66 -66
  24. package/core/cli/nginx.js +199 -199
  25. package/core/cli/route.js +120 -120
  26. package/core/cli/view.js +55 -36
  27. package/core/config.d.ts +3 -3
  28. package/core/config.js +111 -111
  29. package/core/csrf.d.ts +3 -3
  30. package/core/csrf.js +114 -114
  31. package/core/database.d.ts +15 -15
  32. package/core/database.js +636 -636
  33. package/core/debug.d.ts +3 -3
  34. package/core/debug.js +249 -249
  35. package/core/hash.d.ts +3 -3
  36. package/core/hash.js +194 -194
  37. package/core/html.d.ts +42 -0
  38. package/core/html.js +217 -0
  39. package/core/index.d.ts +1176 -1071
  40. package/core/logger.d.ts +3 -3
  41. package/core/logger.js +127 -124
  42. package/core/middleware.d.ts +3 -3
  43. package/core/middleware.js +28 -28
  44. package/core/model.d.ts +19 -19
  45. package/core/model.js +600 -600
  46. package/core/queue.d.ts +13 -13
  47. package/core/queue.js +172 -172
  48. package/core/ratelimit.d.ts +3 -3
  49. package/core/ratelimit.js +145 -145
  50. package/core/redis.d.ts +21 -21
  51. package/core/redis.js +230 -230
  52. package/core/render-cache.js +212 -0
  53. package/core/render.d.ts +3 -3
  54. package/core/render.js +199 -555
  55. package/core/router.d.ts +3 -3
  56. package/core/router.js +171 -171
  57. package/core/seo.d.ts +3 -3
  58. package/core/seo.js +106 -106
  59. package/core/swagger.d.ts +3 -3
  60. package/core/swagger.js +60 -60
  61. package/core/upload.d.ts +13 -13
  62. package/core/upload.js +102 -102
  63. package/core/util/colors.js +82 -82
  64. package/core/validate.d.ts +15 -15
  65. package/core/validate.js +364 -364
  66. package/core/view-loader.js +162 -0
  67. package/core/vite.d.ts +3 -3
  68. package/core/vite.js +145 -145
  69. package/core/ws.d.ts +13 -13
  70. package/core/ws.js +245 -245
  71. package/index.js +18 -18
  72. package/jsconfig.json +15 -15
  73. package/package.json +85 -86
  74. package/production.md +273 -273
  75. package/public/css/bluebird.min.css +1 -1
  76. package/public/js/bluebird-client.js +1780 -1662
  77. package/public/js/bluebird.min.js +1072 -1072
  78. package/app/views/about.html +0 -161
  79. package/app/views/dashboard.html +0 -140
  80. package/app/views/index.html +0 -150
  81. package/app/views/login.html +0 -144
@@ -1,287 +1,287 @@
1
- #!/usr/bin/env node
2
-
3
- import fs from "node:fs";
4
- import path from "node:path";
5
- import net from "node:net";
6
- import colors from "../util/colors.js";
7
-
8
- /**
9
- * Parses .env file into key-value map.
10
- * @returns {Record<string, string>}
11
- */
12
- function parseEnv() {
13
- const envPath = path.resolve(process.cwd(), ".env");
14
- const env = {};
15
- if (fs.existsSync(envPath)) {
16
- const lines = fs.readFileSync(envPath, "utf-8").split("\n");
17
- for (const line of lines) {
18
- const trimmed = line.trim();
19
- if (trimmed && !trimmed.startsWith("#") && trimmed.includes("=")) {
20
- const idx = trimmed.indexOf("=");
21
- const key = trimmed.substring(0, idx).trim();
22
- let val = trimmed.substring(idx + 1).trim();
23
- if (
24
- (val.startsWith('"') && val.endsWith('"')) ||
25
- (val.startsWith("'") && val.endsWith("'"))
26
- ) {
27
- val = val.slice(1, -1);
28
- }
29
- env[key] = val;
30
- }
31
- }
32
- }
33
- return env;
34
- }
35
-
36
- /**
37
- * Checks if a TCP port is currently open for binding on localhost.
38
- * @param {number} port
39
- * @returns {Promise<boolean>} Resolves to true if available, false if in use.
40
- */
41
- function isPortAvailable(port) {
42
- return new Promise((resolve) => {
43
- const server = net.createServer();
44
- server.once("error", () => {
45
- resolve(false);
46
- });
47
- server.once("listening", () => {
48
- server.close(() => resolve(true));
49
- });
50
- server.listen(port, "127.0.0.1");
51
- });
52
- }
53
-
54
- /**
55
- * Finds a representative static file in public/ directory.
56
- * @returns {string|null}
57
- */
58
- function findSampleStaticAsset() {
59
- const publicDir = path.resolve(process.cwd(), "public");
60
- if (!fs.existsSync(publicDir)) return null;
61
-
62
- const candidates = [
63
- "css/style.css",
64
- "js/index.js",
65
- "favicon.ico",
66
- "images/logo.png",
67
- ];
68
-
69
- for (const candidate of candidates) {
70
- if (fs.existsSync(path.join(publicDir, candidate))) {
71
- return candidate;
72
- }
73
- }
74
-
75
- try {
76
- const files = fs.readdirSync(publicDir, { recursive: true });
77
- for (const f of files) {
78
- const full = path.join(publicDir, f);
79
- if (fs.statSync(full).isFile()) {
80
- return f.replace(/\\/g, "/");
81
- }
82
- }
83
- } catch {}
84
-
85
- return null;
86
- }
87
-
88
- /**
89
- * Formats file permissions mode (e.g. 0600, 0755).
90
- * @param {string} filePath
91
- * @returns {string}
92
- */
93
- function getOctalPermissions(filePath) {
94
- try {
95
- const stats = fs.statSync(filePath);
96
- return "0" + (stats.mode & 0o777).toString(8);
97
- } catch {
98
- return "unknown";
99
- }
100
- }
101
-
102
- /**
103
- * Runs the Blue Bird Doctor diagnostic suite.
104
- */
105
- export async function runDoctor() {
106
- console.log(colors.bold.cyan("============================================================="));
107
- console.log(colors.bold.cyan(" Blue Bird System & Security Health Diagnostic (Doctor)"));
108
- console.log(colors.bold.cyan("============================================================="));
109
- console.log("");
110
-
111
- const env = parseEnv();
112
- const envPath = path.resolve(process.cwd(), ".env");
113
- const projectDir = process.cwd();
114
- const isLinux = process.platform === "linux";
115
- const port = parseInt(env.PORT || "3000", 10);
116
- let appUrl = (env.APP_URL || `http://localhost:${port}`).replace(/\/$/, "");
117
- if (
118
- (appUrl === "http://localhost" || appUrl === "http://127.0.0.1") &&
119
- port !== 80
120
- ) {
121
- appUrl = `http://localhost:${port}`;
122
- }
123
-
124
- let issuesFound = 0;
125
- let warningsFound = 0;
126
-
127
- console.log(colors.bold("[1/5] Environment & Configuration (.env):"));
128
- if (!fs.existsSync(envPath)) {
129
- console.log(colors.red(" [FAIL] .env file is missing in project root."));
130
- console.log(colors.gray(" Run 'npx bluebird-js' or copy .env_example to .env."));
131
- issuesFound++;
132
- } else {
133
- console.log(colors.green(" [PASS] .env file exists."));
134
-
135
- if (isLinux) {
136
- const envMode = getOctalPermissions(envPath);
137
- if (envMode !== "0600" && envMode !== "0400") {
138
- console.log(colors.yellow(` [WARN] .env permissions are '${envMode}'. Recommended mode is '0600' (chmod 600 .env).`));
139
- warningsFound++;
140
- } else {
141
- console.log(colors.green(` [PASS] .env file permissions are strictly isolated (${envMode}).`));
142
- }
143
- }
144
-
145
- if (!env.JWT_SECRET || env.JWT_SECRET.length < 16) {
146
- console.log(colors.yellow(" [WARN] JWT_SECRET is missing or shorter than 16 characters."));
147
- warningsFound++;
148
- } else {
149
- console.log(colors.green(" [PASS] JWT_SECRET is configured."));
150
- }
151
- }
152
- console.log("");
153
-
154
- console.log(colors.bold("[2/5] Filesystem Hierarchy Standard & Static Asset Structure:"));
155
- if (isLinux) {
156
- if (projectDir.startsWith("/home/")) {
157
- console.log(colors.yellow(" [WARN] Project is deployed inside '/home/user/'."));
158
- console.log(colors.gray(" Recommended FHS production standard is '/var/www/<project>' or '/srv/<project>'"));
159
- console.log(colors.gray(" to prevent path traversal restrictions for unprivileged containers (nginx UID 101)."));
160
- warningsFound++;
161
- } else {
162
- console.log(colors.green(" [PASS] Project directory follows recommended FHS location."));
163
- }
164
- }
165
-
166
- const publicDir = path.resolve(process.cwd(), "public");
167
- if (!fs.existsSync(publicDir)) {
168
- console.log(colors.yellow(" [WARN] 'public/' directory is missing. Static assets will not be served by Nginx."));
169
- warningsFound++;
170
- } else {
171
- console.log(colors.green(" [PASS] 'public/' directory exists."));
172
- const sampleAsset = findSampleStaticAsset();
173
- if (sampleAsset) {
174
- console.log(colors.green(` [PASS] Detected sample static asset: 'public/${sampleAsset}'`));
175
- } else {
176
- console.log(colors.yellow(" [WARN] No static files found inside 'public/'."));
177
- warningsFound++;
178
- }
179
- }
180
-
181
- const appDir = path.resolve(process.cwd(), "app");
182
- if (!fs.existsSync(appDir)) {
183
- console.log(colors.red(" [FAIL] 'app/' directory is missing."));
184
- issuesFound++;
185
- } else {
186
- console.log(colors.green(" [PASS] 'app/' directory exists."));
187
- }
188
- console.log("");
189
-
190
- console.log(colors.bold("[3/5] Port Availability & Binding:"));
191
- const portFree = await isPortAvailable(port);
192
- if (portFree) {
193
- console.log(colors.green(` [INFO] Port ${port} is currently free and available for binding.`));
194
- } else {
195
- console.log(colors.cyan(` [INFO] Port ${port} is currently in use (application server or container is active).`));
196
- }
197
- console.log("");
198
-
199
- console.log(colors.bold("[4/5] Live HTTP Smoke Test (Health & Static Delivery):"));
200
- const sampleAsset = findSampleStaticAsset();
201
- const testUrls = [
202
- { name: "API Health Endpoint", url: `${appUrl}/api/health`, isApi: true },
203
- ];
204
- if (sampleAsset) {
205
- testUrls.push({
206
- name: `Static Asset (/${sampleAsset})`,
207
- url: `${appUrl}/${sampleAsset}`,
208
- isApi: false,
209
- });
210
- }
211
-
212
- let serverReachable = false;
213
-
214
- for (const item of testUrls) {
215
- try {
216
- const controller = new AbortController();
217
- const timeoutId = setTimeout(() => controller.abort(), 3000);
218
- const res = await fetch(item.url, { signal: controller.signal });
219
- clearTimeout(timeoutId);
220
-
221
- serverReachable = true;
222
-
223
- if (res.status === 200) {
224
- console.log(colors.green(` [PASS] ${item.name} returned HTTP 200 OK.`));
225
- } else if (res.status === 403) {
226
- console.log(colors.red(` [FAIL] ${item.name} returned HTTP 403 Forbidden.`));
227
- console.log(colors.yellow(" Cause: Unprivileged Nginx worker (UID 101) lacks path traversal (+x) or read (+r) permissions."));
228
- console.log(colors.yellow(" Remediation: Run the following commands on your host:"));
229
- console.log(colors.white(` chmod 755 ${projectDir}`));
230
- console.log(colors.white(" find public -type d -exec chmod 755 {} +"));
231
- console.log(colors.white(" find public -type f -exec chmod 644 {} +"));
232
- issuesFound++;
233
- } else if (res.status === 404) {
234
- console.log(colors.red(` [FAIL] ${item.name} returned HTTP 404 Not Found.`));
235
- console.log(colors.yellow(" Cause: Resource or route not found."));
236
- issuesFound++;
237
- } else {
238
- console.log(colors.yellow(` [WARN] ${item.name} returned HTTP ${res.status}.`));
239
- warningsFound++;
240
- }
241
- } catch (err) {
242
- if (err.name === "AbortError") {
243
- console.log(colors.yellow(` [WARN] Request to ${item.name} (${item.url}) timed out after 3s.`));
244
- } else {
245
- console.log(colors.gray(` [INFO] Cannot connect to ${item.name} at ${item.url} (${err.code || err.message}).`));
246
- }
247
- }
248
- }
249
-
250
- if (!serverReachable) {
251
- console.log(colors.gray(" [INFO] Application server is not running locally. Start it with:"));
252
- console.log(colors.gray(" Development: npm run dev"));
253
- console.log(colors.gray(" Production: npm start (or 'pm2 start ecosystem.config.cjs')"));
254
- }
255
- console.log("");
256
-
257
- console.log(colors.bold("[5/5] Database & Cache Architecture:"));
258
- const rawDbType = (env.DB_TYPE || "").toLowerCase().trim();
259
- let dbType = "sqlite";
260
- if (["sqlite", "sqlite3", "sql", "better-sqlite3", "better-sqlite", "lite"].includes(rawDbType)) {
261
- dbType = "sqlite";
262
- } else if (["postgres", "postgresql", "pg", "psql", "pgsql", "postgre", "postgr", "psgr"].includes(rawDbType)) {
263
- dbType = "postgres";
264
- } else if (["mysql", "mariadb", "maria", "my"].includes(rawDbType)) {
265
- dbType = "mysql";
266
- } else if (["none", "no", "false", "null", "0"].includes(rawDbType)) {
267
- dbType = "none";
268
- }
269
- console.log(colors.green(` [INFO] Database Type: ${dbType.toUpperCase()}`));
270
- const cacheMode = (env.CACHE_MODE || "memory").toLowerCase();
271
- console.log(colors.green(` [INFO] Cache Mode: ${cacheMode.toUpperCase()}`));
272
- console.log("");
273
-
274
- console.log(colors.bold.cyan("============================================================="));
275
- if (issuesFound === 0 && warningsFound === 0) {
276
- console.log(colors.bold.green(" Diagnostic Summary: All checks passed with zero issues!"));
277
- } else if (issuesFound === 0) {
278
- console.log(colors.bold.yellow(` Diagnostic Summary: System is operational with ${warningsFound} warning(s).`));
279
- } else {
280
- console.log(colors.bold.red(` Diagnostic Summary: Found ${issuesFound} error(s) and ${warningsFound} warning(s).`));
281
- }
282
- console.log(colors.bold.cyan("============================================================="));
283
- }
284
-
285
- if (import.meta.url === `file://${process.argv[1]}` || process.argv[1]?.endsWith("doctor.js") || process.argv[2] === "doctor") {
286
- runDoctor();
287
- }
1
+ #!/usr/bin/env node
2
+
3
+ import fs from "node:fs";
4
+ import path from "node:path";
5
+ import net from "node:net";
6
+ import colors from "../util/colors.js";
7
+
8
+ /**
9
+ * Parses .env file into key-value map.
10
+ * @returns {Record<string, string>}
11
+ */
12
+ function parseEnv() {
13
+ const envPath = path.resolve(process.cwd(), ".env");
14
+ const env = {};
15
+ if (fs.existsSync(envPath)) {
16
+ const lines = fs.readFileSync(envPath, "utf-8").split("\n");
17
+ for (const line of lines) {
18
+ const trimmed = line.trim();
19
+ if (trimmed && !trimmed.startsWith("#") && trimmed.includes("=")) {
20
+ const idx = trimmed.indexOf("=");
21
+ const key = trimmed.substring(0, idx).trim();
22
+ let val = trimmed.substring(idx + 1).trim();
23
+ if (
24
+ (val.startsWith('"') && val.endsWith('"')) ||
25
+ (val.startsWith("'") && val.endsWith("'"))
26
+ ) {
27
+ val = val.slice(1, -1);
28
+ }
29
+ env[key] = val;
30
+ }
31
+ }
32
+ }
33
+ return env;
34
+ }
35
+
36
+ /**
37
+ * Checks if a TCP port is currently open for binding on localhost.
38
+ * @param {number} port
39
+ * @returns {Promise<boolean>} Resolves to true if available, false if in use.
40
+ */
41
+ function isPortAvailable(port) {
42
+ return new Promise((resolve) => {
43
+ const server = net.createServer();
44
+ server.once("error", () => {
45
+ resolve(false);
46
+ });
47
+ server.once("listening", () => {
48
+ server.close(() => resolve(true));
49
+ });
50
+ server.listen(port, "127.0.0.1");
51
+ });
52
+ }
53
+
54
+ /**
55
+ * Finds a representative static file in public/ directory.
56
+ * @returns {string|null}
57
+ */
58
+ function findSampleStaticAsset() {
59
+ const publicDir = path.resolve(process.cwd(), "public");
60
+ if (!fs.existsSync(publicDir)) return null;
61
+
62
+ const candidates = [
63
+ "css/style.css",
64
+ "js/index.js",
65
+ "favicon.ico",
66
+ "images/logo.png",
67
+ ];
68
+
69
+ for (const candidate of candidates) {
70
+ if (fs.existsSync(path.join(publicDir, candidate))) {
71
+ return candidate;
72
+ }
73
+ }
74
+
75
+ try {
76
+ const files = fs.readdirSync(publicDir, { recursive: true });
77
+ for (const f of files) {
78
+ const full = path.join(publicDir, f);
79
+ if (fs.statSync(full).isFile()) {
80
+ return f.replace(/\\/g, "/");
81
+ }
82
+ }
83
+ } catch {}
84
+
85
+ return null;
86
+ }
87
+
88
+ /**
89
+ * Formats file permissions mode (e.g. 0600, 0755).
90
+ * @param {string} filePath
91
+ * @returns {string}
92
+ */
93
+ function getOctalPermissions(filePath) {
94
+ try {
95
+ const stats = fs.statSync(filePath);
96
+ return "0" + (stats.mode & 0o777).toString(8);
97
+ } catch {
98
+ return "unknown";
99
+ }
100
+ }
101
+
102
+ /**
103
+ * Runs the Blue Bird Doctor diagnostic suite.
104
+ */
105
+ export async function runDoctor() {
106
+ console.log(colors.bold.cyan("============================================================="));
107
+ console.log(colors.bold.cyan(" Blue Bird System & Security Health Diagnostic (Doctor)"));
108
+ console.log(colors.bold.cyan("============================================================="));
109
+ console.log("");
110
+
111
+ const env = parseEnv();
112
+ const envPath = path.resolve(process.cwd(), ".env");
113
+ const projectDir = process.cwd();
114
+ const isLinux = process.platform === "linux";
115
+ const port = parseInt(env.PORT || "3000", 10);
116
+ let appUrl = (env.APP_URL || `http://localhost:${port}`).replace(/\/$/, "");
117
+ if (
118
+ (appUrl === "http://localhost" || appUrl === "http://127.0.0.1") &&
119
+ port !== 80
120
+ ) {
121
+ appUrl = `http://localhost:${port}`;
122
+ }
123
+
124
+ let issuesFound = 0;
125
+ let warningsFound = 0;
126
+
127
+ console.log(colors.bold("[1/5] Environment & Configuration (.env):"));
128
+ if (!fs.existsSync(envPath)) {
129
+ console.log(colors.red(" [FAIL] .env file is missing in project root."));
130
+ console.log(colors.gray(" Run 'npx bluebird-js' or copy .env_example to .env."));
131
+ issuesFound++;
132
+ } else {
133
+ console.log(colors.green(" [PASS] .env file exists."));
134
+
135
+ if (isLinux) {
136
+ const envMode = getOctalPermissions(envPath);
137
+ if (envMode !== "0600" && envMode !== "0400") {
138
+ console.log(colors.yellow(` [WARN] .env permissions are '${envMode}'. Recommended mode is '0600' (chmod 600 .env).`));
139
+ warningsFound++;
140
+ } else {
141
+ console.log(colors.green(` [PASS] .env file permissions are strictly isolated (${envMode}).`));
142
+ }
143
+ }
144
+
145
+ if (!env.JWT_SECRET || env.JWT_SECRET.length < 16) {
146
+ console.log(colors.yellow(" [WARN] JWT_SECRET is missing or shorter than 16 characters."));
147
+ warningsFound++;
148
+ } else {
149
+ console.log(colors.green(" [PASS] JWT_SECRET is configured."));
150
+ }
151
+ }
152
+ console.log("");
153
+
154
+ console.log(colors.bold("[2/5] Filesystem Hierarchy Standard & Static Asset Structure:"));
155
+ if (isLinux) {
156
+ if (projectDir.startsWith("/home/")) {
157
+ console.log(colors.yellow(" [WARN] Project is deployed inside '/home/user/'."));
158
+ console.log(colors.gray(" Recommended FHS production standard is '/var/www/<project>' or '/srv/<project>'"));
159
+ console.log(colors.gray(" to prevent path traversal restrictions for unprivileged containers (nginx UID 101)."));
160
+ warningsFound++;
161
+ } else {
162
+ console.log(colors.green(" [PASS] Project directory follows recommended FHS location."));
163
+ }
164
+ }
165
+
166
+ const publicDir = path.resolve(process.cwd(), "public");
167
+ if (!fs.existsSync(publicDir)) {
168
+ console.log(colors.yellow(" [WARN] 'public/' directory is missing. Static assets will not be served by Nginx."));
169
+ warningsFound++;
170
+ } else {
171
+ console.log(colors.green(" [PASS] 'public/' directory exists."));
172
+ const sampleAsset = findSampleStaticAsset();
173
+ if (sampleAsset) {
174
+ console.log(colors.green(` [PASS] Detected sample static asset: 'public/${sampleAsset}'`));
175
+ } else {
176
+ console.log(colors.yellow(" [WARN] No static files found inside 'public/'."));
177
+ warningsFound++;
178
+ }
179
+ }
180
+
181
+ const appDir = path.resolve(process.cwd(), "app");
182
+ if (!fs.existsSync(appDir)) {
183
+ console.log(colors.red(" [FAIL] 'app/' directory is missing."));
184
+ issuesFound++;
185
+ } else {
186
+ console.log(colors.green(" [PASS] 'app/' directory exists."));
187
+ }
188
+ console.log("");
189
+
190
+ console.log(colors.bold("[3/5] Port Availability & Binding:"));
191
+ const portFree = await isPortAvailable(port);
192
+ if (portFree) {
193
+ console.log(colors.green(` [INFO] Port ${port} is currently free and available for binding.`));
194
+ } else {
195
+ console.log(colors.cyan(` [INFO] Port ${port} is currently in use (application server or container is active).`));
196
+ }
197
+ console.log("");
198
+
199
+ console.log(colors.bold("[4/5] Live HTTP Smoke Test (Health & Static Delivery):"));
200
+ const sampleAsset = findSampleStaticAsset();
201
+ const testUrls = [
202
+ { name: "API Health Endpoint", url: `${appUrl}/api/health`, isApi: true },
203
+ ];
204
+ if (sampleAsset) {
205
+ testUrls.push({
206
+ name: `Static Asset (/${sampleAsset})`,
207
+ url: `${appUrl}/${sampleAsset}`,
208
+ isApi: false,
209
+ });
210
+ }
211
+
212
+ let serverReachable = false;
213
+
214
+ for (const item of testUrls) {
215
+ try {
216
+ const controller = new AbortController();
217
+ const timeoutId = setTimeout(() => controller.abort(), 3000);
218
+ const res = await fetch(item.url, { signal: controller.signal });
219
+ clearTimeout(timeoutId);
220
+
221
+ serverReachable = true;
222
+
223
+ if (res.status === 200) {
224
+ console.log(colors.green(` [PASS] ${item.name} returned HTTP 200 OK.`));
225
+ } else if (res.status === 403) {
226
+ console.log(colors.red(` [FAIL] ${item.name} returned HTTP 403 Forbidden.`));
227
+ console.log(colors.yellow(" Cause: Unprivileged Nginx worker (UID 101) lacks path traversal (+x) or read (+r) permissions."));
228
+ console.log(colors.yellow(" Remediation: Run the following commands on your host:"));
229
+ console.log(colors.white(` chmod 755 ${projectDir}`));
230
+ console.log(colors.white(" find public -type d -exec chmod 755 {} +"));
231
+ console.log(colors.white(" find public -type f -exec chmod 644 {} +"));
232
+ issuesFound++;
233
+ } else if (res.status === 404) {
234
+ console.log(colors.red(` [FAIL] ${item.name} returned HTTP 404 Not Found.`));
235
+ console.log(colors.yellow(" Cause: Resource or route not found."));
236
+ issuesFound++;
237
+ } else {
238
+ console.log(colors.yellow(` [WARN] ${item.name} returned HTTP ${res.status}.`));
239
+ warningsFound++;
240
+ }
241
+ } catch (err) {
242
+ if (err.name === "AbortError") {
243
+ console.log(colors.yellow(` [WARN] Request to ${item.name} (${item.url}) timed out after 3s.`));
244
+ } else {
245
+ console.log(colors.gray(` [INFO] Cannot connect to ${item.name} at ${item.url} (${err.code || err.message}).`));
246
+ }
247
+ }
248
+ }
249
+
250
+ if (!serverReachable) {
251
+ console.log(colors.gray(" [INFO] Application server is not running locally. Start it with:"));
252
+ console.log(colors.gray(" Development: npm run dev"));
253
+ console.log(colors.gray(" Production: npm start (or 'pm2 start ecosystem.config.cjs')"));
254
+ }
255
+ console.log("");
256
+
257
+ console.log(colors.bold("[5/5] Database & Cache Architecture:"));
258
+ const rawDbType = (env.DB_TYPE || "").toLowerCase().trim();
259
+ let dbType = "sqlite";
260
+ if (["sqlite", "sqlite3", "sql", "better-sqlite3", "better-sqlite", "lite"].includes(rawDbType)) {
261
+ dbType = "sqlite";
262
+ } else if (["postgres", "postgresql", "pg", "psql", "pgsql", "postgre", "postgr", "psgr"].includes(rawDbType)) {
263
+ dbType = "postgres";
264
+ } else if (["mysql", "mariadb", "maria", "my"].includes(rawDbType)) {
265
+ dbType = "mysql";
266
+ } else if (["none", "no", "false", "null", "0"].includes(rawDbType)) {
267
+ dbType = "none";
268
+ }
269
+ console.log(colors.green(` [INFO] Database Type: ${dbType.toUpperCase()}`));
270
+ const cacheMode = (env.CACHE_MODE || "memory").toLowerCase();
271
+ console.log(colors.green(` [INFO] Cache Mode: ${cacheMode.toUpperCase()}`));
272
+ console.log("");
273
+
274
+ console.log(colors.bold.cyan("============================================================="));
275
+ if (issuesFound === 0 && warningsFound === 0) {
276
+ console.log(colors.bold.green(" Diagnostic Summary: All checks passed with zero issues!"));
277
+ } else if (issuesFound === 0) {
278
+ console.log(colors.bold.yellow(` Diagnostic Summary: System is operational with ${warningsFound} warning(s).`));
279
+ } else {
280
+ console.log(colors.bold.red(` Diagnostic Summary: Found ${issuesFound} error(s) and ${warningsFound} warning(s).`));
281
+ }
282
+ console.log(colors.bold.cyan("============================================================="));
283
+ }
284
+
285
+ if (import.meta.url === `file://${process.argv[1]}` || process.argv[1]?.endsWith("doctor.js") || process.argv[2] === "doctor") {
286
+ runDoctor();
287
+ }