@arkstack/driver-express 0.15.0 → 0.15.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 (2) hide show
  1. package/dist/index.js +31 -4
  2. package/package.json +6 -6
package/dist/index.js CHANGED
@@ -1,6 +1,7 @@
1
1
  import express from "express";
2
2
  import { ArkstackKitDriver } from "@arkstack/contract";
3
- import { ErrorHandler, Logger, RequestException, env, renderError, resolveRuntimeModule } from "@arkstack/common";
3
+ import { ErrorHandler, Logger, RequestException, devTlsCredentials, env, localNetworkAddress, renderError, resolveRuntimeModule } from "@arkstack/common";
4
+ import https from "node:https";
4
5
  import { resolveMiddleware } from "@arkstack/http";
5
6
  import ngrok from "@ngrok/ngrok";
6
7
  import { Router as Router$2 } from "clear-router/express";
@@ -191,9 +192,11 @@ var ExpressDriver = class extends ArkstackKitDriver {
191
192
  */
192
193
  async start(app, port) {
193
194
  const host = env("APP_HOST", env("HOST", "0.0.0.0"));
195
+ const secure = env("APP_SECURE", false) === true;
194
196
  const tunneled = env("TUNNEL", false);
195
- app.listen(port, host, async () => {
196
- let log = [Logger.log([["Server is running on", "white"], [`http://${host}:${port}`, "cyan"]], " ", false)];
197
+ const scheme = secure ? "https" : "http";
198
+ const onListen = async () => {
199
+ let log = startupLogLines(scheme, host, port);
197
200
  if (tunneled === true) {
198
201
  const url = (await ngrok.forward({
199
202
  addr: port,
@@ -208,8 +211,32 @@ var ExpressDriver = class extends ArkstackKitDriver {
208
211
  }
209
212
  }
210
213
  console.log(log.join("\n"));
211
- });
214
+ };
215
+ if (secure) {
216
+ const credentials = await devTlsCredentials();
217
+ https.createServer({
218
+ key: credentials.key,
219
+ cert: credentials.cert
220
+ }, app).listen(port, host, onListen);
221
+ return;
222
+ }
223
+ app.listen(port, host, onListen);
224
+ }
225
+ };
226
+ /**
227
+ * Build the "Server is running" startup lines, adding a local-network URL when
228
+ * the server is bound to all interfaces (`0.0.0.0`/`::`) so it is reachable from
229
+ * other devices.
230
+ */
231
+ const startupLogLines = (scheme, host, port) => {
232
+ const bindsAll = host === "0.0.0.0" || host === "::";
233
+ const localHost = bindsAll ? "localhost" : host;
234
+ const lines = [Logger.log([["Server is running on", "white"], [`${scheme}://${localHost}:${port}`, "cyan"]], " ", false)];
235
+ if (bindsAll) {
236
+ const address = localNetworkAddress();
237
+ if (address) lines.push(Logger.log([["Network access via", "white"], [`${scheme}://${address}:${port}`, "cyan"]], " ", false));
212
238
  }
239
+ return lines;
213
240
  };
214
241
  //#endregion
215
242
  export { ExpressDriver, Router, defaultErrorHandler };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@arkstack/driver-express",
3
- "version": "0.15.0",
3
+ "version": "0.15.2",
4
4
  "type": "module",
5
5
  "description": "Express driver for Arkstack, providing Express-based runtime integration for the framework.",
6
6
  "homepage": "https://arkstack.toneflix.net",
@@ -43,14 +43,14 @@
43
43
  "express-rate-limit": "^8.4.1",
44
44
  "multer": "^2.1.1",
45
45
  "resora": "^1.3.27",
46
- "@arkstack/contract": "^0.15.0"
46
+ "@arkstack/contract": "^0.15.2"
47
47
  },
48
48
  "peerDependencies": {
49
49
  "express": "^5.2.1",
50
- "@arkstack/foundry": "^0.15.0",
51
- "@arkstack/common": "^0.15.0",
52
- "@arkstack/inertia": "^0.15.0",
53
- "@arkstack/auth": "^0.15.0"
50
+ "@arkstack/foundry": "^0.15.2",
51
+ "@arkstack/auth": "^0.15.2",
52
+ "@arkstack/common": "^0.15.2",
53
+ "@arkstack/inertia": "^0.15.2"
54
54
  },
55
55
  "peerDependenciesMeta": {
56
56
  "@arkstack/auth": {