bini-server 1.0.6 → 1.0.8
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/cli.js +89 -58
- package/dist/index.js +2 -2
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -1,6 +1,19 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __esm = (fn, res) => function __init() {
|
|
5
|
+
return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
|
|
6
|
+
};
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
2
11
|
|
|
3
12
|
// src/index.ts
|
|
13
|
+
var src_exports = {};
|
|
14
|
+
__export(src_exports, {
|
|
15
|
+
start: () => start
|
|
16
|
+
});
|
|
4
17
|
import http from "http";
|
|
5
18
|
import fs from "fs";
|
|
6
19
|
import path from "path";
|
|
@@ -21,22 +34,6 @@ function detectEnvFiles(root) {
|
|
|
21
34
|
".env"
|
|
22
35
|
].filter((f) => fs.existsSync(path.join(root, f)));
|
|
23
36
|
}
|
|
24
|
-
var DEFAULT_PORT = parseInt(process.env.PORT ?? "3000", 10);
|
|
25
|
-
var BODY_TIMEOUT = parseInt(process.env.BINI_BODY_TIMEOUT_SECS ?? "30", 10) * 1e3;
|
|
26
|
-
var HANDLER_TIMEOUT = parseInt(process.env.BINI_HANDLER_TIMEOUT_SECS ?? "30", 10) * 1e3;
|
|
27
|
-
var BODY_SIZE_LIMIT = parseInt(process.env.BINI_BODY_SIZE_LIMIT ?? String(10 * 1024 * 1024), 10);
|
|
28
|
-
var API_DIR = path.join(process.cwd(), process.env.BINI_API_DIR ?? "src/app/api");
|
|
29
|
-
var DIST_DIR = path.join(process.cwd(), process.env.BINI_DIST_DIR ?? "dist");
|
|
30
|
-
var API_EXTS = /* @__PURE__ */ new Set([".ts", ".js", ".mjs", ".cjs"]);
|
|
31
|
-
var C = {
|
|
32
|
-
CYAN: "\x1B[36m",
|
|
33
|
-
RESET: "\x1B[0m",
|
|
34
|
-
GREEN: "\x1B[32m",
|
|
35
|
-
RED: "\x1B[31m",
|
|
36
|
-
YELLOW: "\x1B[33m",
|
|
37
|
-
BOLD: "\x1B[1m",
|
|
38
|
-
DIM: "\x1B[2m"
|
|
39
|
-
};
|
|
40
37
|
function getNetworkIp() {
|
|
41
38
|
const ifaces = os.networkInterfaces();
|
|
42
39
|
const SKIP = /docker|veth|br-|lo|loopback|vmnet|vbox|utun|tun|tap/i;
|
|
@@ -59,12 +56,12 @@ function getNetworkIp() {
|
|
|
59
56
|
return null;
|
|
60
57
|
}
|
|
61
58
|
function printBanner(port) {
|
|
62
|
-
const
|
|
59
|
+
const envFiles2 = detectEnvFiles(process.cwd());
|
|
63
60
|
const networkIp = getNetworkIp();
|
|
64
61
|
console.log(`
|
|
65
62
|
${C.BOLD}${C.CYAN}\xDF Bini.js${C.RESET} (production)`);
|
|
66
|
-
if (
|
|
67
|
-
console.log(` ${C.GREEN}\u279C${C.RESET} Environments: ${
|
|
63
|
+
if (envFiles2.length > 0) {
|
|
64
|
+
console.log(` ${C.GREEN}\u279C${C.RESET} Environments: ${envFiles2.join(", ")}`);
|
|
68
65
|
}
|
|
69
66
|
console.log(` ${C.GREEN}\u279C${C.RESET} Local: ${C.CYAN}http://localhost:${port}/${C.RESET}`);
|
|
70
67
|
if (networkIp) {
|
|
@@ -81,17 +78,17 @@ async function isPortFree(port) {
|
|
|
81
78
|
server.listen(port, "0.0.0.0");
|
|
82
79
|
});
|
|
83
80
|
}
|
|
84
|
-
async function findFreePort(
|
|
85
|
-
for (let port =
|
|
81
|
+
async function findFreePort(start3) {
|
|
82
|
+
for (let port = start3; port < start3 + 100; port++) {
|
|
86
83
|
if (await isPortFree(port)) {
|
|
87
|
-
if (port !==
|
|
84
|
+
if (port !== start3) {
|
|
88
85
|
console.log(`
|
|
89
|
-
${C.YELLOW}\u26A0${C.RESET} Port ${
|
|
86
|
+
${C.YELLOW}\u26A0${C.RESET} Port ${start3} in use \u2014 using ${port} instead.`);
|
|
90
87
|
}
|
|
91
88
|
return port;
|
|
92
89
|
}
|
|
93
90
|
}
|
|
94
|
-
throw new Error(`No free port found in range ${
|
|
91
|
+
throw new Error(`No free port found in range ${start3}\u2013${start3 + 99}`);
|
|
95
92
|
}
|
|
96
93
|
function startKeyboardLoop(port) {
|
|
97
94
|
const rl = readline.createInterface({ input: process.stdin });
|
|
@@ -100,8 +97,8 @@ function startKeyboardLoop(port) {
|
|
|
100
97
|
case "h":
|
|
101
98
|
console.log("");
|
|
102
99
|
console.log(" Shortcuts");
|
|
103
|
-
console.log(` ${C.DIM}
|
|
104
|
-
console.log(` ${C.DIM}
|
|
100
|
+
console.log(` ${C.DIM}press ${C.RESET}o + enter${C.DIM} to open in browser${C.RESET}`);
|
|
101
|
+
console.log(` ${C.DIM}press ${C.RESET}q + enter${C.DIM} to quit${C.RESET}`);
|
|
105
102
|
console.log("");
|
|
106
103
|
break;
|
|
107
104
|
case "o": {
|
|
@@ -174,7 +171,6 @@ function matchRoute(pattern, pathname) {
|
|
|
174
171
|
}
|
|
175
172
|
return params;
|
|
176
173
|
}
|
|
177
|
-
var moduleCache = /* @__PURE__ */ new Map();
|
|
178
174
|
async function importHandler(filePath) {
|
|
179
175
|
let mtime = 0;
|
|
180
176
|
try {
|
|
@@ -231,16 +227,9 @@ function normalizeHeaders(raw) {
|
|
|
231
227
|
}
|
|
232
228
|
return out;
|
|
233
229
|
}
|
|
234
|
-
var CORS_HEADERS = {
|
|
235
|
-
"Access-Control-Allow-Origin": "*",
|
|
236
|
-
"Access-Control-Allow-Methods": "GET,POST,PUT,PATCH,DELETE,OPTIONS",
|
|
237
|
-
"Access-Control-Allow-Headers": "Content-Type,Authorization,X-Request-ID",
|
|
238
|
-
"Vary": "Origin"
|
|
239
|
-
};
|
|
240
230
|
function invokeHono(honoApp, request) {
|
|
241
231
|
return honoApp.fetch(request, process.env);
|
|
242
232
|
}
|
|
243
|
-
var routeCache = null;
|
|
244
233
|
async function handleApiRequest(req, res, next) {
|
|
245
234
|
if (req.method === "OPTIONS") {
|
|
246
235
|
res.writeHead(204, { ...CORS_HEADERS, "Access-Control-Max-Age": "86400" });
|
|
@@ -335,29 +324,6 @@ async function handleApiRequest(req, res, next) {
|
|
|
335
324
|
res.writeHead(webRes.status, finalHeaders);
|
|
336
325
|
res.end(Buffer.from(await webRes.arrayBuffer()));
|
|
337
326
|
}
|
|
338
|
-
var MIME = {
|
|
339
|
-
".html": "text/html; charset=utf-8",
|
|
340
|
-
".js": "application/javascript",
|
|
341
|
-
".mjs": "application/javascript",
|
|
342
|
-
".css": "text/css",
|
|
343
|
-
".json": "application/json",
|
|
344
|
-
".png": "image/png",
|
|
345
|
-
".jpg": "image/jpeg",
|
|
346
|
-
".jpeg": "image/jpeg",
|
|
347
|
-
".gif": "image/gif",
|
|
348
|
-
".svg": "image/svg+xml",
|
|
349
|
-
".ico": "image/x-icon",
|
|
350
|
-
".webp": "image/webp",
|
|
351
|
-
".avif": "image/avif",
|
|
352
|
-
".woff": "font/woff",
|
|
353
|
-
".woff2": "font/woff2",
|
|
354
|
-
".ttf": "font/ttf",
|
|
355
|
-
".eot": "application/vnd.ms-fontobject",
|
|
356
|
-
".txt": "text/plain",
|
|
357
|
-
".xml": "application/xml",
|
|
358
|
-
".webmanifest": "application/manifest+json",
|
|
359
|
-
".map": "application/json"
|
|
360
|
-
};
|
|
361
327
|
function getETag(stat) {
|
|
362
328
|
return crypto.createHash("md5").update(`${stat.size}-${stat.mtimeMs}`).digest("hex").slice(0, 16);
|
|
363
329
|
}
|
|
@@ -475,9 +441,74 @@ async function start() {
|
|
|
475
441
|
process.on("SIGTERM", shutdown);
|
|
476
442
|
process.on("SIGINT", shutdown);
|
|
477
443
|
}
|
|
444
|
+
var DEFAULT_PORT, BODY_TIMEOUT, HANDLER_TIMEOUT, BODY_SIZE_LIMIT, API_DIR, DIST_DIR, API_EXTS, C, moduleCache, CORS_HEADERS, routeCache, MIME;
|
|
445
|
+
var init_src = __esm({
|
|
446
|
+
"src/index.ts"() {
|
|
447
|
+
"use strict";
|
|
448
|
+
DEFAULT_PORT = parseInt(process.env.PORT ?? "3000", 10);
|
|
449
|
+
BODY_TIMEOUT = parseInt(process.env.BINI_BODY_TIMEOUT_SECS ?? "30", 10) * 1e3;
|
|
450
|
+
HANDLER_TIMEOUT = parseInt(process.env.BINI_HANDLER_TIMEOUT_SECS ?? "30", 10) * 1e3;
|
|
451
|
+
BODY_SIZE_LIMIT = parseInt(process.env.BINI_BODY_SIZE_LIMIT ?? String(10 * 1024 * 1024), 10);
|
|
452
|
+
API_DIR = path.join(process.cwd(), process.env.BINI_API_DIR ?? "src/app/api");
|
|
453
|
+
DIST_DIR = path.join(process.cwd(), process.env.BINI_DIST_DIR ?? "dist");
|
|
454
|
+
API_EXTS = /* @__PURE__ */ new Set([".ts", ".js", ".mjs", ".cjs"]);
|
|
455
|
+
C = {
|
|
456
|
+
CYAN: "\x1B[36m",
|
|
457
|
+
RESET: "\x1B[0m",
|
|
458
|
+
GREEN: "\x1B[32m",
|
|
459
|
+
RED: "\x1B[31m",
|
|
460
|
+
YELLOW: "\x1B[33m",
|
|
461
|
+
BOLD: "\x1B[1m",
|
|
462
|
+
DIM: "\x1B[2m"
|
|
463
|
+
};
|
|
464
|
+
moduleCache = /* @__PURE__ */ new Map();
|
|
465
|
+
CORS_HEADERS = {
|
|
466
|
+
"Access-Control-Allow-Origin": "*",
|
|
467
|
+
"Access-Control-Allow-Methods": "GET,POST,PUT,PATCH,DELETE,OPTIONS",
|
|
468
|
+
"Access-Control-Allow-Headers": "Content-Type,Authorization,X-Request-ID",
|
|
469
|
+
"Vary": "Origin"
|
|
470
|
+
};
|
|
471
|
+
routeCache = null;
|
|
472
|
+
MIME = {
|
|
473
|
+
".html": "text/html; charset=utf-8",
|
|
474
|
+
".js": "application/javascript",
|
|
475
|
+
".mjs": "application/javascript",
|
|
476
|
+
".css": "text/css",
|
|
477
|
+
".json": "application/json",
|
|
478
|
+
".png": "image/png",
|
|
479
|
+
".jpg": "image/jpeg",
|
|
480
|
+
".jpeg": "image/jpeg",
|
|
481
|
+
".gif": "image/gif",
|
|
482
|
+
".svg": "image/svg+xml",
|
|
483
|
+
".ico": "image/x-icon",
|
|
484
|
+
".webp": "image/webp",
|
|
485
|
+
".avif": "image/avif",
|
|
486
|
+
".woff": "font/woff",
|
|
487
|
+
".woff2": "font/woff2",
|
|
488
|
+
".ttf": "font/ttf",
|
|
489
|
+
".eot": "application/vnd.ms-fontobject",
|
|
490
|
+
".txt": "text/plain",
|
|
491
|
+
".xml": "application/xml",
|
|
492
|
+
".webmanifest": "application/manifest+json",
|
|
493
|
+
".map": "application/json"
|
|
494
|
+
};
|
|
495
|
+
}
|
|
496
|
+
});
|
|
478
497
|
|
|
479
498
|
// src/cli.ts
|
|
480
|
-
|
|
499
|
+
import { existsSync } from "fs";
|
|
500
|
+
process.env.NODE_ENV = "production";
|
|
501
|
+
var envFiles = [
|
|
502
|
+
".env.local",
|
|
503
|
+
".env.production.local",
|
|
504
|
+
".env.production",
|
|
505
|
+
".env"
|
|
506
|
+
];
|
|
507
|
+
for (const file of envFiles) {
|
|
508
|
+
if (existsSync(file)) process.loadEnvFile(file);
|
|
509
|
+
}
|
|
510
|
+
var { start: start2 } = await Promise.resolve().then(() => (init_src(), src_exports));
|
|
511
|
+
start2().catch((err) => {
|
|
481
512
|
console.error(err);
|
|
482
513
|
process.exit(1);
|
|
483
514
|
});
|
package/dist/index.js
CHANGED
|
@@ -98,8 +98,8 @@ function startKeyboardLoop(port) {
|
|
|
98
98
|
case "h":
|
|
99
99
|
console.log("");
|
|
100
100
|
console.log(" Shortcuts");
|
|
101
|
-
console.log(` ${C.DIM}
|
|
102
|
-
console.log(` ${C.DIM}
|
|
101
|
+
console.log(` ${C.DIM}press ${C.RESET}o + enter${C.DIM} to open in browser${C.RESET}`);
|
|
102
|
+
console.log(` ${C.DIM}press ${C.RESET}q + enter${C.DIM} to quit${C.RESET}`);
|
|
103
103
|
console.log("");
|
|
104
104
|
break;
|
|
105
105
|
case "o": {
|