@demoscript/cli 1.1.8 → 1.1.10

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/bundle.cjs CHANGED
@@ -71088,6 +71088,12 @@ function processRestStepWithOpenApi(step, spec, baseUrl) {
71088
71088
  };
71089
71089
  }
71090
71090
 
71091
+ // ../shared/dist/variables/index.js
71092
+ var BODYLESS_METHODS = ["GET", "HEAD", "OPTIONS"];
71093
+ function methodSupportsBody(method) {
71094
+ return !BODYLESS_METHODS.includes(method.toUpperCase());
71095
+ }
71096
+
71091
71097
  // src/server/rest-proxy.ts
71092
71098
  function createRestProxy() {
71093
71099
  return async (req, res) => {
@@ -71111,7 +71117,7 @@ function createRestProxy() {
71111
71117
  method,
71112
71118
  headers: fetchHeaders
71113
71119
  };
71114
- if (body && method !== "GET") {
71120
+ if (body && methodSupportsBody(method)) {
71115
71121
  fetchOptions.body = JSON.stringify(body);
71116
71122
  }
71117
71123
  const response = await fetch(absoluteUrl, fetchOptions);
@@ -74201,17 +74207,48 @@ var source_default = chalk;
74201
74207
 
74202
74208
  // src/commands/serve.ts
74203
74209
  var __dirname3 = (0, import_path3.dirname)((0, import_url2.fileURLToPath)(importMetaUrl));
74204
- function getNetworkUrl(port) {
74210
+ function getHostIp() {
74205
74211
  const nets = (0, import_os.networkInterfaces)();
74206
74212
  for (const name of Object.keys(nets)) {
74207
74213
  for (const net of nets[name] || []) {
74208
74214
  if (net.family === "IPv4" && !net.internal) {
74209
- return `http://${net.address}:${port}`;
74215
+ return net.address;
74210
74216
  }
74211
74217
  }
74212
74218
  }
74213
74219
  return null;
74214
74220
  }
74221
+ function getNetworkUrl(port) {
74222
+ const hostIp = getHostIp();
74223
+ return hostIp ? `http://${hostIp}:${port}` : null;
74224
+ }
74225
+ function replaceLocalhostWithIp(url, hostIp) {
74226
+ return url.replace(/localhost/gi, hostIp).replace(/127\.0\.0\.1/g, hostIp);
74227
+ }
74228
+ function processConfigForNetwork(config, hostIp, autoReplace) {
74229
+ if (!hostIp) return config;
74230
+ const processValue = (value) => {
74231
+ if (typeof value === "string") {
74232
+ let result = value.replace(/\$\{host_ip\}/gi, hostIp);
74233
+ if (autoReplace) {
74234
+ result = replaceLocalhostWithIp(result, hostIp);
74235
+ }
74236
+ return result;
74237
+ }
74238
+ if (Array.isArray(value)) {
74239
+ return value.map(processValue);
74240
+ }
74241
+ if (value && typeof value === "object") {
74242
+ const processed = {};
74243
+ for (const [k, v] of Object.entries(value)) {
74244
+ processed[k] = processValue(v);
74245
+ }
74246
+ return processed;
74247
+ }
74248
+ return value;
74249
+ };
74250
+ return processValue(config);
74251
+ }
74215
74252
  async function serve(demoPath, options) {
74216
74253
  const { port, host, open: open3, watch: watch2 } = options;
74217
74254
  const resolvedPath = (0, import_path3.resolve)(process.cwd(), demoPath);
@@ -74222,10 +74259,16 @@ async function serve(demoPath, options) {
74222
74259
  let { config, recordings, openapiSpec } = await loadDemo(demoFile);
74223
74260
  console.log(source_default.green(` Loaded: ${config.title}`));
74224
74261
  console.log(source_default.gray(` Steps: ${config.steps.length}`));
74262
+ const hostIp = getHostIp();
74263
+ const autoReplaceLocalhost = host === "0.0.0.0";
74264
+ if (hostIp && autoReplaceLocalhost) {
74265
+ console.log(source_default.gray(` Host IP: ${hostIp} (auto-replacing localhost)`));
74266
+ }
74225
74267
  const app = (0, import_express.default)();
74226
74268
  app.use(import_express.default.json());
74227
74269
  app.get("/api/demo", (_req, res) => {
74228
- res.json({ config, recordings, openapiSpec });
74270
+ const processedConfig = processConfigForNetwork(config, hostIp, autoReplaceLocalhost);
74271
+ res.json({ config: processedConfig, recordings, openapiSpec });
74229
74272
  });
74230
74273
  const wsClients = /* @__PURE__ */ new Set();
74231
74274
  app.post("/api/execute", createRestProxy());
@@ -74249,7 +74292,7 @@ async function serve(demoPath, options) {
74249
74292
  }
74250
74293
  }
74251
74294
  app.all("/sandbox", sandboxHandler);
74252
- app.all("/sandbox/*", sandboxHandler);
74295
+ app.all("/sandbox/*path", sandboxHandler);
74253
74296
  app.post("/api/open-browser", async (req, res) => {
74254
74297
  try {
74255
74298
  const { url } = req.body;
@@ -74362,7 +74405,8 @@ async function serve(demoPath, options) {
74362
74405
  recordings = reloaded.recordings;
74363
74406
  openapiSpec = reloaded.openapiSpec;
74364
74407
  console.log(source_default.green(` Reloaded: ${config.title}`));
74365
- const message = JSON.stringify({ type: "reload", config, recordings, openapiSpec });
74408
+ const processedConfig = processConfigForNetwork(config, hostIp, autoReplaceLocalhost);
74409
+ const message = JSON.stringify({ type: "reload", config: processedConfig, recordings, openapiSpec });
74366
74410
  for (const client of wsClients) {
74367
74411
  if (client.readyState === import_websocket.default.OPEN) {
74368
74412
  client.send(message);