4bnode 4.2.0 → 4.2.1

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.
@@ -15,13 +15,25 @@ NODE_ENV=development
15
15
  RATE_LIMIT_WINDOW_MS=900000
16
16
  RATE_LIMIT_MAX=500
17
17
 
18
+ # ── API key gate ──
19
+ # Every API route (login and register included) needs a valid x-api-key header.
20
+ # Create / revoke keys in the /_dev dashboard → Security → API keys.
21
+ # API_KEY_REQUIRED: "off" disables the gate (default: on).
22
+ # API_KEY_PUBLIC_PATHS: comma-separated path prefixes that never need a key
23
+ # (/docs is always public), e.g. /health,/webhooks/stripe
24
+ # API_KEY_REQUIRED=on
25
+ # API_KEY_PUBLIC_PATHS=
26
+
18
27
  # ── Bonjour / mDNS service discovery ──
19
28
  # The app advertises itself on the local network so other devices can find it by
20
- # name (http://<host>.local:<port>) without hard-coded IPs. On by default.
21
- # BONJOUR_ENABLED: "off" disables advertising entirely.
29
+ # name (http://<host>.local:<port>) without hard-coded IPs. Off by default.
30
+ # BONJOUR_ENABLED: "on" turns advertising on (it is OFF by default).
31
+ # BONJOUR_INTERFACE: network to advertise on when several are connected,
32
+ # e.g. en0 (Wi-Fi) or en7 (Ethernet). Blank = all networks.
22
33
  # BONJOUR_NAME: custom service name shown to other devices (default: app + host).
23
34
  # BONJOUR_TYPE: service type without the leading underscore (default: "http").
24
- # BONJOUR_ENABLED=off
35
+ # BONJOUR_ENABLED=on
36
+ # BONJOUR_INTERFACE=en0
25
37
  # BONJOUR_NAME=My App
26
38
  # BONJOUR_TYPE=http
27
39
 
@@ -33,3 +45,11 @@ RATE_LIMIT_MAX=500
33
45
  # any hosted environment.
34
46
  # _4BNODE_DASHBOARD=off
35
47
  # _4BNODE_ALLOW_REMOTE=1
48
+
49
+ # ── Serial devices (Arduino / ESP32) ──
50
+ # Boards are detected when plugged in. An unknown board is added as a device
51
+ # automatically (opening a port resets most boards). Configure in the dashboard.
52
+ # SERIAL_AUTO_ADD: "off" only lists new boards, without adding them (default: on).
53
+ # SERIAL_DEFAULT_BAUD: baud rate used to identify and connect auto-added boards.
54
+ # SERIAL_AUTO_ADD=on
55
+ # SERIAL_DEFAULT_BAUD=115200
@@ -3,6 +3,7 @@
3
3
  .env.*
4
4
  !.env.example
5
5
  src/docs-auth.json
6
+ src/api-keys.json
6
7
  .4bnode/.passkey
7
8
 
8
9
  # Dependencies
package/skeleton/index.js CHANGED
@@ -9,6 +9,7 @@ import rateLimit from "express-rate-limit";
9
9
  import { createInterface } from "readline";
10
10
  import { notFound, errorHandler } from "./src/middleware/errorHandler.js";
11
11
  import { startAdvertising, destroyDiscovery } from "./src/discovery.js";
12
+ import { apiKeyGate } from "./src/middleware/apiKey.js";
12
13
 
13
14
  // ── Environment ─────────────────────────────────────
14
15
  dotenv.config();
@@ -41,6 +42,8 @@ const dashboardEnabled =
41
42
  if (dashboardEnabled) {
42
43
  try {
43
44
  const devApi = await import("./.4bnode/dev-api.js");
45
+ // In-memory request stats for the dashboard's live overview.
46
+ if (devApi.requestMetrics) app.use(devApi.requestMetrics);
44
47
  app.use("/_dev", devApi.default);
45
48
  } catch {}
46
49
  }
@@ -84,6 +87,11 @@ app.use(apiLimiter);
84
87
  // ── Static Files ────────────────────────────────────
85
88
  app.use(express.static(path.join(__dirname, "public")));
86
89
 
90
+ // ── API key gate ────────────────────────────────────
91
+ // Every API route (login/register included) needs a valid x-api-key header.
92
+ // Manage keys in the /_dev dashboard → Security. API_KEY_REQUIRED=off disables.
93
+ app.use(apiKeyGate);
94
+
87
95
  // ── Helpers ─────────────────────────────────────────
88
96
  function getLocalNetworkIp() {
89
97
  const interfaces = os.networkInterfaces();