4bnode 4.0.0 → 4.0.2

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 (37) hide show
  1. package/README.md +10 -0
  2. package/add-login.js +2 -2
  3. package/index.js +57 -5
  4. package/lib/indexFile.js +60 -13
  5. package/package.json +1 -1
  6. package/skeleton/.4bnode/assets/js/App.js +115 -0
  7. package/skeleton/.4bnode/assets/js/Root.js +44 -0
  8. package/skeleton/.4bnode/assets/js/components/Modal.js +52 -0
  9. package/skeleton/.4bnode/assets/js/components/Sidebar.js +68 -0
  10. package/skeleton/.4bnode/assets/js/components/ToastContainer.js +15 -0
  11. package/skeleton/.4bnode/assets/js/context.js +7 -0
  12. package/skeleton/.4bnode/assets/js/lib.js +83 -0
  13. package/skeleton/.4bnode/assets/js/main.js +5 -0
  14. package/skeleton/.4bnode/assets/js/pages/ApiTesterPage.js +1594 -0
  15. package/skeleton/.4bnode/assets/js/pages/DashboardPage.js +435 -0
  16. package/skeleton/.4bnode/assets/js/pages/DatabasePage.js +461 -0
  17. package/skeleton/.4bnode/assets/js/pages/EnvironmentPage.js +141 -0
  18. package/skeleton/.4bnode/assets/js/pages/RealtimePage.js +186 -0
  19. package/skeleton/.4bnode/assets/js/pages/RoutesPage.js +1656 -0
  20. package/skeleton/.4bnode/assets/js/pages/SchemasPage.js +901 -0
  21. package/skeleton/.4bnode/assets/js/pages/SerialPortPage.js +170 -0
  22. package/skeleton/.4bnode/assets/js/screens/PasskeyScreen.js +105 -0
  23. package/skeleton/.4bnode/assets/js/screens/SplashScreen.js +66 -0
  24. package/skeleton/{dev-api.js → .4bnode/dev-api.js} +259 -114
  25. package/skeleton/.4bnode/ui.html +1556 -0
  26. package/skeleton/index.js +62 -16
  27. package/skeleton/package.json +1 -1
  28. package/skeleton/public/index.html +290 -7586
  29. /package/skeleton/{public → .4bnode/assets}/fonts/NotoSans-Bold.woff2 +0 -0
  30. /package/skeleton/{public → .4bnode/assets}/fonts/NotoSans-Light.woff2 +0 -0
  31. /package/skeleton/{public → .4bnode/assets}/fonts/NotoSans-Medium.woff2 +0 -0
  32. /package/skeleton/{public → .4bnode/assets}/fonts/NotoSans-Regular.woff2 +0 -0
  33. /package/skeleton/{public → .4bnode/assets}/fonts/NotoSans-SemiBold.woff2 +0 -0
  34. /package/skeleton/{public → .4bnode/assets}/images/mongo.png +0 -0
  35. /package/skeleton/{public → .4bnode/assets}/images/mysql.png +0 -0
  36. /package/skeleton/{public → .4bnode/assets}/images/postgresql.png +0 -0
  37. /package/skeleton/{public → .4bnode/assets}/images/sqlite.png +0 -0
package/skeleton/index.js CHANGED
@@ -1,33 +1,36 @@
1
1
  import express from "express";
2
2
  import dotenv from "dotenv";
3
3
  import path from "path";
4
+ import fs from "fs";
4
5
  import cors from "cors";
5
6
  import os from "os";
7
+ import { createInterface } from "readline";
6
8
 
9
+ // ── Environment ─────────────────────────────────────
7
10
  const env = process.env.NODE_ENV || "development";
8
11
  dotenv.config({ path: `.env.${env}` });
9
12
 
10
13
  const app = express();
11
14
  const port = process.env.PORT || 3000;
15
+ const __dirname = path.resolve();
12
16
 
13
- // Middleware
17
+ // ── Middleware ───────────────────────────────────────
14
18
  app.use(express.json({ limit: "50mb" }));
15
19
  app.use(express.urlencoded({ extended: true, limit: "50mb" }));
16
20
  app.use(cors({ origin: "*" }));
17
21
 
18
- // Dev dashboard (only in development)
22
+ // ── Dev Dashboard (development only) ────────────────
19
23
  if (env === "development") {
20
24
  try {
21
- const devApi = await import("./dev-api.js");
25
+ const devApi = await import("./.4bnode/dev-api.js");
22
26
  app.use("/_dev", devApi.default);
23
27
  } catch {}
24
28
  }
25
29
 
26
- // Serve static files from the public directory
27
- const __dirname = path.resolve();
30
+ // ── Static Files ────────────────────────────────────
28
31
  app.use(express.static(path.join(__dirname, "public")));
29
32
 
30
- // Get local network IP address
33
+ // ── Helpers ─────────────────────────────────────────
31
34
  function getLocalNetworkIp() {
32
35
  const interfaces = os.networkInterfaces();
33
36
  for (const name of Object.keys(interfaces)) {
@@ -40,13 +43,56 @@ function getLocalNetworkIp() {
40
43
  return null;
41
44
  }
42
45
 
43
- // Start server
44
- app.listen(port, () => {
45
- const localIp = getLocalNetworkIp();
46
- console.log(`App is running on http://localhost:${port}`);
47
- if (localIp) {
48
- console.log(
49
- `App is also accessible on your local network at http://${localIp}:${port}`
50
- );
51
- }
52
- });
46
+ function updateEnvPort(newPort) {
47
+ const envFile = `.env.${env}`;
48
+ try {
49
+ if (fs.existsSync(envFile)) {
50
+ let content = fs.readFileSync(envFile, "utf8");
51
+ if (content.match(/^PORT=.*/m)) {
52
+ content = content.replace(/^PORT=.*/m, `PORT=${newPort}`);
53
+ } else {
54
+ content += `\nPORT=${newPort}`;
55
+ }
56
+ fs.writeFileSync(envFile, content, "utf8");
57
+ }
58
+ } catch {}
59
+ }
60
+
61
+ function askPort(busyPort) {
62
+ return new Promise((resolve) => {
63
+ const rl = createInterface({ input: process.stdin, output: process.stdout });
64
+ console.log(`\nPort ${busyPort} is already in use.`);
65
+ rl.question(`Press Enter to use ${busyPort + 1}, or type a port number: `, (answer) => {
66
+ rl.close();
67
+ const custom = parseInt(answer.trim(), 10);
68
+ resolve(custom && custom > 0 ? custom : busyPort + 1);
69
+ });
70
+ });
71
+ }
72
+
73
+ // ── Start Server ────────────────────────────────────
74
+ async function startServer(tryPort) {
75
+ const listener = app.listen(tryPort);
76
+ listener.on("listening", () => {
77
+ const localIp = getLocalNetworkIp();
78
+ console.log(`App is running on http://localhost:${tryPort}`);
79
+ if (localIp) {
80
+ console.log(`App is also accessible on your local network at http://${localIp}:${tryPort}`);
81
+ }
82
+ if (tryPort !== Number(port)) {
83
+ updateEnvPort(tryPort);
84
+ console.log(`Updated .env.${env} with PORT=${tryPort}`);
85
+ }
86
+ });
87
+ listener.on("error", async (err) => {
88
+ if (err.code === "EADDRINUSE") {
89
+ const nextPort = await askPort(tryPort);
90
+ startServer(nextPort);
91
+ } else {
92
+ console.error(err);
93
+ process.exit(1);
94
+ }
95
+ });
96
+ }
97
+
98
+ startServer(Number(port));
@@ -10,7 +10,7 @@
10
10
  "nodemonConfig": {
11
11
  "watch": ["."],
12
12
  "ext": "js,mjs,cjs",
13
- "ignore": ["node_modules/", "package.json", "package-lock.json"]
13
+ "ignore": ["node_modules/", "package.json", "package-lock.json", ".4bnode/"]
14
14
  },
15
15
  "dependencies": {
16
16
  "express": "^5.2.1",