jskelet 0.2.5 → 0.3.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 (106) hide show
  1. package/AGENTS.md +132 -132
  2. package/CHANGELOG.md +403 -383
  3. package/LICENSE +21 -21
  4. package/bin/jskelet.mjs +103 -103
  5. package/docs/01-baslangic.md +285 -285
  6. package/docs/02-mimari.md +293 -287
  7. package/docs/03-routing.md +486 -480
  8. package/docs/04-render-ve-sablonlar.md +490 -490
  9. package/docs/05-islands.md +482 -482
  10. package/docs/06-cache.md +1231 -1209
  11. package/docs/07-yapilandirma.md +44 -21
  12. package/docs/08-build.md +366 -366
  13. package/docs/09-dev-araclari.md +335 -335
  14. package/docs/10-dagitim.md +329 -329
  15. package/docs/11-tasima.md +1 -0
  16. package/docs/12-panel-ve-oturum.md +384 -384
  17. package/docs/README.md +105 -105
  18. package/docs/en/01-getting-started.md +292 -292
  19. package/docs/en/02-architecture.md +311 -305
  20. package/docs/en/03-routing.md +503 -497
  21. package/docs/en/04-rendering.md +504 -504
  22. package/docs/en/05-islands.md +492 -492
  23. package/docs/en/06-caching.md +1197 -1198
  24. package/docs/en/07-configuration.md +1009 -986
  25. package/docs/en/08-build.md +383 -383
  26. package/docs/en/09-dev-tools.md +342 -342
  27. package/docs/en/10-deployment.md +332 -332
  28. package/docs/en/11-migration.md +360 -359
  29. package/docs/en/12-dashboards-and-sessions.md +392 -392
  30. package/docs/en/README.md +112 -112
  31. package/package.json +102 -102
  32. package/src/build/ensure-build.mjs +15 -15
  33. package/src/build/paths.mjs +143 -143
  34. package/src/build/resolve-peer.mjs +36 -36
  35. package/src/build/tasks/client.mjs +268 -268
  36. package/src/build/tasks/css.mjs +124 -124
  37. package/src/build/tasks/fonts.mjs +146 -146
  38. package/src/build/tasks/icons.mjs +224 -224
  39. package/src/build/tasks/images.mjs +244 -244
  40. package/src/build/tasks/precompress.mjs +78 -78
  41. package/src/client/{cache-panel → admin}/i18n.js +756 -670
  42. package/src/client/{cache-panel → admin}/login.html +74 -74
  43. package/src/client/{cache-panel → admin}/panel.css +804 -756
  44. package/src/client/admin/panel.html +486 -0
  45. package/src/client/{cache-panel → admin}/panel.js +1242 -915
  46. package/src/client/devtools/report.html +185 -185
  47. package/src/client/devtools/report.js +725 -725
  48. package/src/client/dom.js +95 -95
  49. package/src/client/form.js +192 -192
  50. package/src/client/index.js +35 -35
  51. package/src/client/registry.js +297 -297
  52. package/src/client/safe-image.js +91 -91
  53. package/src/client/store.js +36 -36
  54. package/src/client/swap.js +188 -188
  55. package/src/config/defaults.js +16 -7
  56. package/src/config/index.js +38 -22
  57. package/src/config/pattern.js +107 -107
  58. package/src/http/control-flow.js +71 -71
  59. package/src/http/cookies.js +257 -257
  60. package/src/http/request-cache.js +46 -46
  61. package/src/http/request-context.js +162 -162
  62. package/src/index.js +83 -83
  63. package/src/init.mjs +221 -221
  64. package/src/log.mjs +58 -0
  65. package/src/runtime/alias-hooks.mjs +119 -119
  66. package/src/runtime/register.mjs +4 -4
  67. package/src/server/admin/actions.js +229 -0
  68. package/src/server/admin/auth.js +125 -0
  69. package/src/server/admin/event-log.js +151 -0
  70. package/src/server/admin/gate.js +209 -0
  71. package/src/server/admin/inventory.js +188 -0
  72. package/src/server/admin/mount.js +56 -0
  73. package/src/server/admin/router.js +216 -0
  74. package/src/server/admin/snapshot.js +126 -0
  75. package/src/server/assets.js +147 -147
  76. package/src/server/cache-deps.js +42 -42
  77. package/src/server/cloudflare.js +607 -607
  78. package/src/server/create-app.js +295 -291
  79. package/src/server/data-cache.js +462 -462
  80. package/src/server/dev/report.js +369 -369
  81. package/src/server/dev/socket.js +170 -170
  82. package/src/server/dev/version-check.mjs +139 -139
  83. package/src/server/html-cache.js +817 -817
  84. package/src/server/metadata.js +102 -102
  85. package/src/server/middleware/compression.js +205 -205
  86. package/src/server/middleware/csrf.js +134 -134
  87. package/src/server/middleware/dev-gate.js +62 -62
  88. package/src/server/middleware/headers.js +37 -37
  89. package/src/server/middleware/redirects.js +32 -32
  90. package/src/server/middleware/static-precompressed.js +100 -100
  91. package/src/server/middleware/trailing-slash.js +53 -0
  92. package/src/server/middleware/upstream-proxy.js +141 -141
  93. package/src/server/prewarm.js +601 -601
  94. package/src/server/redis.js +569 -569
  95. package/src/server/router.js +128 -128
  96. package/src/server/status-page.js +164 -164
  97. package/src/server/upstream-limiter.js +376 -376
  98. package/src/server/upstream-tracking.js +166 -166
  99. package/src/start.mjs +7 -7
  100. package/src/templates/layout.ejs +44 -44
  101. package/src/version.mjs +31 -31
  102. package/src/views/components/loader.js +85 -85
  103. package/src/views/helpers/html.js +102 -102
  104. package/src/views/helpers/tags.js +245 -245
  105. package/src/client/cache-panel/panel.html +0 -308
  106. package/src/server/cache-panel.js +0 -759
@@ -0,0 +1,151 @@
1
+ /**
2
+ * Admin paneli için süreç içi olay kuyruğu.
3
+ *
4
+ * Kaynaklar: HTTP `finish` middleware'i ve `log.mjs` aboneliği. Gövde yok —
5
+ * yalnızca meta. Admin kapalıyken bu modül yüklenmez.
6
+ */
7
+ import * as log from "../../log.mjs";
8
+ import { getConfig } from "../../config/index.js";
9
+
10
+ /** @typedef {{ kind: string, id: number, at: number, [key: string]: unknown }} LogEntry */
11
+
12
+ /** @type {LogEntry[]} */
13
+ const ring = [];
14
+
15
+ /** @type {Set<(entry: LogEntry) => void>} */
16
+ const live = new Set();
17
+
18
+ let nextId = 1;
19
+ /** @type {(() => void) | null} */
20
+ let unsubscribeLog = null;
21
+ /** @type {string} */
22
+ let basePath = "/_jskelet/admin";
23
+ /** @type {string} */
24
+ let prewarmUa = "jskelet-prewarm";
25
+ let maxSize = 500;
26
+
27
+ /**
28
+ * @param {{ basePath: string, logSize: number, prewarmUserAgent?: string }} options
29
+ */
30
+ export function configureEventLog(options) {
31
+ basePath = options.basePath;
32
+ maxSize = options.logSize;
33
+ if (options.prewarmUserAgent) prewarmUa = options.prewarmUserAgent;
34
+
35
+ if (!unsubscribeLog) {
36
+ unsubscribeLog = log.subscribe((raw) => {
37
+ // HTTP finish middleware zaten kendi kaydını yazıyor; log.http
38
+ // çift kayıt üretmesin.
39
+ if (raw.kind === "http") return;
40
+ push({
41
+ kind: typeof raw.kind === "string" ? raw.kind : "event",
42
+ scope: raw.scope ?? null,
43
+ message: raw.message ?? "",
44
+ note: raw.note ?? null,
45
+ ms: raw.ms ?? null,
46
+ });
47
+ });
48
+ }
49
+ }
50
+
51
+ /**
52
+ * @param {Omit<LogEntry, "id" | "at"> & { kind: string }} partial
53
+ * @returns {LogEntry}
54
+ */
55
+ export function push(partial) {
56
+ /** @type {LogEntry} */
57
+ const entry = {
58
+ ...partial,
59
+ id: nextId++,
60
+ at: Date.now(),
61
+ };
62
+
63
+ ring.push(entry);
64
+ while (ring.length > maxSize) ring.shift();
65
+
66
+ for (const listener of live) {
67
+ try {
68
+ listener(entry);
69
+ } catch {
70
+ // SSE dinleyicisi paneli düşürmesin.
71
+ }
72
+ }
73
+
74
+ return entry;
75
+ }
76
+
77
+ /**
78
+ * @param {number} [afterId]
79
+ * @param {number} [limit]
80
+ * @returns {LogEntry[]}
81
+ */
82
+ export function list(afterId = 0, limit = 200) {
83
+ const capped = Math.min(Math.max(1, limit), maxSize);
84
+ const filtered = afterId > 0 ? ring.filter((entry) => entry.id > afterId) : ring;
85
+ return filtered.slice(-capped);
86
+ }
87
+
88
+ /**
89
+ * @param {(entry: LogEntry) => void} listener
90
+ * @returns {() => void}
91
+ */
92
+ export function subscribeLive(listener) {
93
+ live.add(listener);
94
+ return () => live.delete(listener);
95
+ }
96
+
97
+ /**
98
+ * HTTP yanıt bitiminde ring'e yazar. Admin yolları ve prewarm UA atlanır.
99
+ *
100
+ * @returns {import('express').RequestHandler}
101
+ */
102
+ export function requestLogMiddleware() {
103
+ const brand = getConfig().brand;
104
+
105
+ /** @type {import('express').RequestHandler} */
106
+ return (req, res, next) => {
107
+ const pathname = req.path || "";
108
+ if (pathname === basePath || pathname.startsWith(`${basePath}/`)) {
109
+ return next();
110
+ }
111
+
112
+ if (req.headers["user-agent"] === (brand.prewarmUserAgent || prewarmUa)) {
113
+ return next();
114
+ }
115
+
116
+ const started = process.hrtime.bigint();
117
+
118
+ res.on("finish", () => {
119
+ const routePath = matchedRoute(req);
120
+ push({
121
+ kind: "http",
122
+ method: req.method,
123
+ url: req.originalUrl,
124
+ path: req.path,
125
+ route: routePath,
126
+ status: res.statusCode,
127
+ ms: Number(process.hrtime.bigint() - started) / 1e6,
128
+ cache: /** @type {string | null} */ (
129
+ res.getHeader(brand.cacheHeader) ?? null
130
+ ),
131
+ });
132
+ });
133
+
134
+ next();
135
+ };
136
+ }
137
+
138
+ /**
139
+ * Express'in eşleştirdiği route deseni (mount + path). Yoksa null.
140
+ *
141
+ * @param {import('express').Request} req
142
+ * @returns {string | null}
143
+ */
144
+ function matchedRoute(req) {
145
+ const layer = /** @type {any} */ (req).route;
146
+ if (!layer || typeof layer.path !== "string") return null;
147
+
148
+ const base = /** @type {any} */ (req).baseUrl || "";
149
+ const pattern = layer.path === "/" ? base || "/" : `${base}${layer.path}`;
150
+ return pattern || null;
151
+ }
@@ -0,0 +1,209 @@
1
+ /**
2
+ * Admin paneli erişim kapısı: IP allowlist, bot UA engeli, ban sayacı.
3
+ *
4
+ * Yasaklı / reddedilen her cevap 404: 401/403 panelin varlığını doğrular.
5
+ */
6
+ import net from "node:net";
7
+
8
+ /** Bilinen crawler / bot imzaları (küçük harf). */
9
+ const BOT_MARKERS = [
10
+ "googlebot",
11
+ "bingbot",
12
+ "slurp",
13
+ "duckduckbot",
14
+ "baiduspider",
15
+ "yandexbot",
16
+ "sogou",
17
+ "exabot",
18
+ "facebot",
19
+ "facebookexternalhit",
20
+ "ia_archiver",
21
+ "applebot",
22
+ "semrushbot",
23
+ "ahrefsbot",
24
+ "mj12bot",
25
+ "dotbot",
26
+ "petalbot",
27
+ "bytespider",
28
+ "gptbot",
29
+ "claudebot",
30
+ "ccbot",
31
+ "amazonbot",
32
+ "twitterbot",
33
+ "linkedinbot",
34
+ "embedly",
35
+ "quora link preview",
36
+ "showyoubot",
37
+ "outbrain",
38
+ "pinterest",
39
+ "redditbot",
40
+ "whatsapp",
41
+ "telegrambot",
42
+ "discordbot",
43
+ "crawler",
44
+ "spider",
45
+ "bot/",
46
+ "bot;",
47
+ ];
48
+
49
+ /** @type {Map<string, { fails: number, bannedUntil: number }>} */
50
+ const offenders = new Map();
51
+
52
+ /**
53
+ * @param {import('express').Request} req
54
+ * @returns {string}
55
+ */
56
+ export function clientKey(req) {
57
+ // `trust proxy` ayarı `req.ip`e yansıyor; ters proxy arkasında doğru IP,
58
+ // doğrudan internete açık bir sunucuda soket adresi kullanılır.
59
+ return req.ip ?? req.socket.remoteAddress ?? "unknown";
60
+ }
61
+
62
+ /**
63
+ * @param {string} ua
64
+ * @returns {boolean}
65
+ */
66
+ export function looksLikeBot(ua) {
67
+ if (!ua) return true;
68
+ const lower = ua.toLowerCase();
69
+ return BOT_MARKERS.some((marker) => lower.includes(marker));
70
+ }
71
+
72
+ /**
73
+ * Exact IP veya CIDR (`10.0.0.0/8`). IPv6 için yalnızca exact eşleşme.
74
+ *
75
+ * @param {string} ip
76
+ * @param {string[]} allowIps
77
+ * @returns {boolean}
78
+ */
79
+ export function ipAllowed(ip, allowIps) {
80
+ if (!allowIps.length) return true;
81
+
82
+ const normalized = normalizeIp(ip);
83
+ if (!normalized) return false;
84
+
85
+ for (const entry of allowIps) {
86
+ if (entry.includes("/")) {
87
+ if (matchCidr(normalized, entry)) return true;
88
+ continue;
89
+ }
90
+ if (normalizeIp(entry) === normalized) return true;
91
+ }
92
+
93
+ return false;
94
+ }
95
+
96
+ /**
97
+ * @param {string} ip
98
+ * @returns {string | null}
99
+ */
100
+ function normalizeIp(ip) {
101
+ if (!ip) return null;
102
+ // Express IPv4-mapped IPv6: `:ffff:127.0.0.1`
103
+ const mapped = ip.startsWith("::ffff:") ? ip.slice(7) : ip;
104
+ return mapped;
105
+ }
106
+
107
+ /**
108
+ * @param {string} ip
109
+ * @param {string} cidr
110
+ * @returns {boolean}
111
+ */
112
+ function matchCidr(ip, cidr) {
113
+ const [network, bitsRaw] = cidr.split("/");
114
+ const bits = Number(bitsRaw);
115
+ if (!Number.isFinite(bits) || bits < 0 || bits > 32) return false;
116
+ if (net.isIPv4(ip) && net.isIPv4(network)) {
117
+ const ipNum = ipv4ToInt(ip);
118
+ const netNum = ipv4ToInt(network);
119
+ if (ipNum === null || netNum === null) return false;
120
+ const mask = bits === 0 ? 0 : (~0 << (32 - bits)) >>> 0;
121
+ return (ipNum & mask) === (netNum & mask);
122
+ }
123
+ return false;
124
+ }
125
+
126
+ /**
127
+ * @param {string} ip
128
+ * @returns {number | null}
129
+ */
130
+ function ipv4ToInt(ip) {
131
+ const parts = ip.split(".").map(Number);
132
+ if (parts.length !== 4 || parts.some((n) => !Number.isFinite(n) || n < 0 || n > 255)) {
133
+ return null;
134
+ }
135
+ return ((parts[0] << 24) | (parts[1] << 16) | (parts[2] << 8) | parts[3]) >>> 0;
136
+ }
137
+
138
+ /**
139
+ * @param {import('express').Request} req
140
+ * @returns {boolean}
141
+ */
142
+ export function banned(req) {
143
+ const record = offenders.get(clientKey(req));
144
+ if (!record) return false;
145
+
146
+ if (record.bannedUntil && Date.now() >= record.bannedUntil) {
147
+ offenders.delete(clientKey(req));
148
+ return false;
149
+ }
150
+
151
+ return record.bannedUntil > 0;
152
+ }
153
+
154
+ /**
155
+ * @param {import('express').Request} req
156
+ * @param {string} reason
157
+ * @param {{ banAttempts: number, banHours: number }} settings
158
+ */
159
+ export function noteFailure(req, reason, settings) {
160
+ const key = clientKey(req);
161
+ const record = offenders.get(key) ?? { fails: 0, bannedUntil: 0 };
162
+ record.fails += 1;
163
+
164
+ if (record.fails >= settings.banAttempts) {
165
+ record.bannedUntil = Date.now() + settings.banHours * 3600_000;
166
+ console.warn(
167
+ `[admin] ${key} banned for ${settings.banHours}h after ` +
168
+ `${record.fails} failed attempts (${reason})`,
169
+ );
170
+ }
171
+
172
+ offenders.set(key, record);
173
+ }
174
+
175
+ /**
176
+ * @param {import('express').Request} req
177
+ */
178
+ export function clearOffender(req) {
179
+ offenders.delete(clientKey(req));
180
+ }
181
+
182
+ /**
183
+ * Kapı middleware'i: ban → IP → bot. Hepsi 404.
184
+ *
185
+ * @param {() => typeof import('../../config/defaults.js').DEFAULT_ADMIN} getSettings
186
+ * @returns {import('express').RequestHandler}
187
+ */
188
+ export function gateMiddleware(getSettings) {
189
+ return (req, res, next) => {
190
+ if (banned(req)) {
191
+ res.status(404).type("text/plain").send("Not Found");
192
+ return;
193
+ }
194
+
195
+ const settings = getSettings();
196
+
197
+ if (!ipAllowed(clientKey(req), settings.allowIps)) {
198
+ res.status(404).type("text/plain").send("Not Found");
199
+ return;
200
+ }
201
+
202
+ if (settings.blockBots && looksLikeBot(String(req.headers["user-agent"] ?? ""))) {
203
+ res.status(404).type("text/plain").send("Not Found");
204
+ return;
205
+ }
206
+
207
+ next();
208
+ };
209
+ }
@@ -0,0 +1,188 @@
1
+ /**
2
+ * Route ve view envanteri — admin paneline salt okunur döküm.
3
+ */
4
+ import fs from "node:fs";
5
+ import path from "node:path";
6
+ import { getConfig } from "../../config/index.js";
7
+ import { list as listLogs } from "./event-log.js";
8
+
9
+ /**
10
+ * Express router stack'ini dolaşır. İç API kırılgan; yalnızca gözlem için.
11
+ *
12
+ * @param {import('express').Express} app
13
+ * @returns {{ method: string, path: string }[]}
14
+ */
15
+ export function listExpressRoutes(app) {
16
+ /** @type {{ method: string, path: string }[]} */
17
+ const out = [];
18
+ const stack = /** @type {any} */ (app)?._router?.stack;
19
+ if (!Array.isArray(stack)) return out;
20
+
21
+ /**
22
+ * @param {any[]} layers
23
+ * @param {string} prefix
24
+ */
25
+ function walk(layers, prefix) {
26
+ for (const layer of layers) {
27
+ if (layer.route) {
28
+ const routePath = joinPath(prefix, layer.route.path);
29
+ const methods = Object.keys(layer.route.methods || {}).filter(
30
+ (name) => layer.route.methods[name],
31
+ );
32
+ for (const method of methods) {
33
+ out.push({ method: method.toUpperCase(), path: routePath });
34
+ }
35
+ continue;
36
+ }
37
+
38
+ if (layer.name === "router" && layer.handle?.stack) {
39
+ const mount = layer.regexp ? regexpToPrefix(layer.regexp) : "";
40
+ walk(layer.handle.stack, joinPath(prefix, mount));
41
+ }
42
+ }
43
+ }
44
+
45
+ walk(stack, "");
46
+ return out.sort((a, b) => a.path.localeCompare(b.path) || a.method.localeCompare(b.method));
47
+ }
48
+
49
+ /**
50
+ * @param {string} a
51
+ * @param {string} b
52
+ * @returns {string}
53
+ */
54
+ function joinPath(a, b) {
55
+ if (!a) return b || "/";
56
+ if (!b || b === "/") return a || "/";
57
+ return `${a.replace(/\/+$/, "")}/${String(b).replace(/^\/+/, "")}`;
58
+ }
59
+
60
+ /**
61
+ * Express mount regexp → okunabilir önek. Tam doğruluk şart değil.
62
+ *
63
+ * @param {RegExp} regexp
64
+ * @returns {string}
65
+ */
66
+ function regexpToPrefix(regexp) {
67
+ const source = regexp.source
68
+ .replace("^\\/", "/")
69
+ .replace("\\/?(?=\\/|$)", "")
70
+ .replace(/\$$/, "")
71
+ .replace(/\\\//g, "/")
72
+ .replace(/\(\?:\(\?=.*$/, "");
73
+ if (!source.startsWith("/")) return "";
74
+ const cleaned = source.replace(/[^a-zA-Z0-9/_\-.:*]/g, "");
75
+ return cleaned || "";
76
+ }
77
+
78
+ /**
79
+ * `routes/` altındaki (veya config.routes listesindeki) modül dosyaları.
80
+ *
81
+ * @returns {{ file: string, relative: string }[]}
82
+ */
83
+ export function listRouteModules() {
84
+ const config = getConfig();
85
+ const root = config.root;
86
+
87
+ const files = config.routes
88
+ ? config.routes.map((entry) => path.resolve(root, entry))
89
+ : discover(config.dirs.routes);
90
+
91
+ return files.map((file) => ({
92
+ file,
93
+ relative: path.relative(root, file).replaceAll("\\", "/"),
94
+ }));
95
+ }
96
+
97
+ /**
98
+ * @param {string} dir
99
+ * @param {string[]} [out]
100
+ * @returns {string[]}
101
+ */
102
+ function discover(dir, out = []) {
103
+ if (!fs.existsSync(dir)) return out;
104
+
105
+ const entries = fs
106
+ .readdirSync(dir, { withFileTypes: true })
107
+ .sort((a, b) => a.name.localeCompare(b.name));
108
+
109
+ for (const entry of entries) {
110
+ const full = path.join(dir, entry.name);
111
+ if (entry.isDirectory()) {
112
+ discover(full, out);
113
+ continue;
114
+ }
115
+ if (!/\.(js|mjs)$/.test(entry.name)) continue;
116
+ if (entry.name.startsWith("_")) continue;
117
+ out.push(full);
118
+ }
119
+
120
+ return out;
121
+ }
122
+
123
+ /**
124
+ * `views/` altındaki şablon ve bileşen dosyaları.
125
+ *
126
+ * @returns {{ relative: string, kind: "ejs" | "js" | "other" }[]}
127
+ */
128
+ export function listViews() {
129
+ const config = getConfig();
130
+ const root = config.dirs.views;
131
+ /** @type {{ relative: string, kind: "ejs" | "js" | "other" }[]} */
132
+ const out = [];
133
+
134
+ /**
135
+ * @param {string} dir
136
+ */
137
+ function walk(dir) {
138
+ if (!fs.existsSync(dir)) return;
139
+ for (const entry of fs.readdirSync(dir, { withFileTypes: true }).sort((a, b) =>
140
+ a.name.localeCompare(b.name),
141
+ )) {
142
+ const full = path.join(dir, entry.name);
143
+ if (entry.isDirectory()) {
144
+ walk(full);
145
+ continue;
146
+ }
147
+ const relative = path.relative(root, full).replaceAll("\\", "/");
148
+ const kind = entry.name.endsWith(".ejs")
149
+ ? "ejs"
150
+ : /\.(js|mjs)$/.test(entry.name)
151
+ ? "js"
152
+ : "other";
153
+ out.push({ relative, kind });
154
+ }
155
+ }
156
+
157
+ walk(root);
158
+ return out;
159
+ }
160
+
161
+ /**
162
+ * Son HTTP log'larından path başına özet.
163
+ *
164
+ * @returns {Record<string, { status: number, ms: number, cache: string | null, at: number, count: number }>}
165
+ */
166
+ export function routeActivity() {
167
+ /** @type {Record<string, { status: number, ms: number, cache: string | null, at: number, count: number }>} */
168
+ const byPath = {};
169
+
170
+ for (const entry of listLogs(0, 500)) {
171
+ if (entry.kind !== "http") continue;
172
+ const key = typeof entry.route === "string" && entry.route
173
+ ? entry.route
174
+ : String(entry.path ?? entry.url ?? "");
175
+ if (!key) continue;
176
+
177
+ const prev = byPath[key];
178
+ byPath[key] = {
179
+ status: Number(entry.status) || 0,
180
+ ms: Number(entry.ms) || 0,
181
+ cache: /** @type {string | null} */ (entry.cache ?? null),
182
+ at: entry.at,
183
+ count: (prev?.count ?? 0) + 1,
184
+ };
185
+ }
186
+
187
+ return byPath;
188
+ }
@@ -0,0 +1,56 @@
1
+ /**
2
+ * Framework yönetim paneli (`/_jskelet/admin`).
3
+ *
4
+ * Dev overlay'den ayrı: `NODE_ENV`'e bakmaz, yalnızca `admin().enabled` /
5
+ * `JSKELET_ADMIN` ile açılır. Kapalıyken modül yüklenmez ve yol yoktur.
6
+ *
7
+ * Şifre süreç başlangıcında üretilir ve log kutusunda bir kez basılır.
8
+ */
9
+ import process from "node:process";
10
+ import * as log from "../../log.mjs";
11
+ import { getConfig } from "../../config/index.js";
12
+ import { PASSWORD } from "./auth.js";
13
+ import { createAdminRouter } from "./router.js";
14
+ import { configureEventLog, requestLogMiddleware } from "./event-log.js";
15
+
16
+ /** @type {typeof import('../../config/defaults.js').DEFAULT_ADMIN} */
17
+ let settings;
18
+
19
+ /**
20
+ * @returns {typeof import('../../config/defaults.js').DEFAULT_ADMIN}
21
+ */
22
+ function getSettings() {
23
+ return settings;
24
+ }
25
+
26
+ /**
27
+ * Paneli uygulamaya bağlar, istek log middleware'ini kurar ve şifreyi loglar.
28
+ *
29
+ * @param {import('express').Express} app
30
+ */
31
+ export function mountAdmin(app) {
32
+ settings = getConfig().admin;
33
+
34
+ configureEventLog({
35
+ basePath: settings.basePath,
36
+ logSize: settings.logSize,
37
+ prewarmUserAgent: String(getConfig().brand.prewarmUserAgent ?? ""),
38
+ });
39
+
40
+ app.use(settings.basePath, createAdminRouter(getSettings, app));
41
+ // Route'lardan önce mount edilir; `finish` anında Express `req.route`
42
+ // doldurmuş olur. Admin yolları ring'e yazılmaz.
43
+ app.use(requestLogMiddleware());
44
+
45
+ const port = process.env.PORT ?? 3000;
46
+ log.box({
47
+ title: "ADMIN",
48
+ lines: [
49
+ `http://localhost:${port}${settings.basePath}`,
50
+ "",
51
+ `password ${PASSWORD}`,
52
+ "",
53
+ "Valid until this process restarts.",
54
+ ],
55
+ });
56
+ }