@lolyjs/core 0.2.0-alpha.32 → 0.2.0-alpha.34

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/index.cjs CHANGED
@@ -9906,8 +9906,8 @@ __export(src_exports, {
9906
9906
  module.exports = __toCommonJS(src_exports);
9907
9907
 
9908
9908
  // src/server.ts
9909
- var import_fs21 = __toESM(require("fs"));
9910
- var import_path27 = __toESM(require("path"));
9909
+ var import_fs22 = __toESM(require("fs"));
9910
+ var import_path28 = __toESM(require("path"));
9911
9911
 
9912
9912
  // modules/server/utils/server-dir.ts
9913
9913
  var import_fs = __toESM(require("fs"));
@@ -10490,7 +10490,7 @@ function matchApiRoute(routes, pathname) {
10490
10490
  if (!match) continue;
10491
10491
  const params = {};
10492
10492
  r.paramNames.forEach((name, idx) => {
10493
- params[name] = match[idx + 1];
10493
+ params[name] = decodeURIComponent(match[idx + 1] || "");
10494
10494
  });
10495
10495
  return { route: r, params };
10496
10496
  }
@@ -12550,7 +12550,7 @@ var ReaddirpStream = class extends import_node_stream.Readable {
12550
12550
  this._directoryFilter = normalizeFilter(opts.directoryFilter);
12551
12551
  const statMethod = opts.lstat ? import_promises.lstat : import_promises.stat;
12552
12552
  if (wantBigintFsStats) {
12553
- this._stat = (path30) => statMethod(path30, { bigint: true });
12553
+ this._stat = (path31) => statMethod(path31, { bigint: true });
12554
12554
  } else {
12555
12555
  this._stat = statMethod;
12556
12556
  }
@@ -12575,8 +12575,8 @@ var ReaddirpStream = class extends import_node_stream.Readable {
12575
12575
  const par = this.parent;
12576
12576
  const fil = par && par.files;
12577
12577
  if (fil && fil.length > 0) {
12578
- const { path: path30, depth } = par;
12579
- const slice = fil.splice(0, batch).map((dirent) => this._formatEntry(dirent, path30));
12578
+ const { path: path31, depth } = par;
12579
+ const slice = fil.splice(0, batch).map((dirent) => this._formatEntry(dirent, path31));
12580
12580
  const awaited = await Promise.all(slice);
12581
12581
  for (const entry of awaited) {
12582
12582
  if (!entry)
@@ -12616,20 +12616,20 @@ var ReaddirpStream = class extends import_node_stream.Readable {
12616
12616
  this.reading = false;
12617
12617
  }
12618
12618
  }
12619
- async _exploreDir(path30, depth) {
12619
+ async _exploreDir(path31, depth) {
12620
12620
  let files;
12621
12621
  try {
12622
- files = await (0, import_promises.readdir)(path30, this._rdOptions);
12622
+ files = await (0, import_promises.readdir)(path31, this._rdOptions);
12623
12623
  } catch (error) {
12624
12624
  this._onError(error);
12625
12625
  }
12626
- return { files, depth, path: path30 };
12626
+ return { files, depth, path: path31 };
12627
12627
  }
12628
- async _formatEntry(dirent, path30) {
12628
+ async _formatEntry(dirent, path31) {
12629
12629
  let entry;
12630
12630
  const basename3 = this._isDirent ? dirent.name : dirent;
12631
12631
  try {
12632
- const fullPath = (0, import_node_path.resolve)((0, import_node_path.join)(path30, basename3));
12632
+ const fullPath = (0, import_node_path.resolve)((0, import_node_path.join)(path31, basename3));
12633
12633
  entry = { path: (0, import_node_path.relative)(this._root, fullPath), fullPath, basename: basename3 };
12634
12634
  entry[this._statsProp] = this._isDirent ? dirent : await this._stat(fullPath);
12635
12635
  } catch (err) {
@@ -13029,16 +13029,16 @@ var delFromSet = (main, prop, item) => {
13029
13029
  };
13030
13030
  var isEmptySet = (val) => val instanceof Set ? val.size === 0 : !val;
13031
13031
  var FsWatchInstances = /* @__PURE__ */ new Map();
13032
- function createFsWatchInstance(path30, options, listener, errHandler, emitRaw) {
13032
+ function createFsWatchInstance(path31, options, listener, errHandler, emitRaw) {
13033
13033
  const handleEvent = (rawEvent, evPath) => {
13034
- listener(path30);
13035
- emitRaw(rawEvent, evPath, { watchedPath: path30 });
13036
- if (evPath && path30 !== evPath) {
13037
- fsWatchBroadcast(sysPath.resolve(path30, evPath), KEY_LISTENERS, sysPath.join(path30, evPath));
13034
+ listener(path31);
13035
+ emitRaw(rawEvent, evPath, { watchedPath: path31 });
13036
+ if (evPath && path31 !== evPath) {
13037
+ fsWatchBroadcast(sysPath.resolve(path31, evPath), KEY_LISTENERS, sysPath.join(path31, evPath));
13038
13038
  }
13039
13039
  };
13040
13040
  try {
13041
- return (0, import_fs16.watch)(path30, {
13041
+ return (0, import_fs16.watch)(path31, {
13042
13042
  persistent: options.persistent
13043
13043
  }, handleEvent);
13044
13044
  } catch (error) {
@@ -13054,12 +13054,12 @@ var fsWatchBroadcast = (fullPath, listenerType, val1, val2, val3) => {
13054
13054
  listener(val1, val2, val3);
13055
13055
  });
13056
13056
  };
13057
- var setFsWatchListener = (path30, fullPath, options, handlers) => {
13057
+ var setFsWatchListener = (path31, fullPath, options, handlers) => {
13058
13058
  const { listener, errHandler, rawEmitter } = handlers;
13059
13059
  let cont = FsWatchInstances.get(fullPath);
13060
13060
  let watcher;
13061
13061
  if (!options.persistent) {
13062
- watcher = createFsWatchInstance(path30, options, listener, errHandler, rawEmitter);
13062
+ watcher = createFsWatchInstance(path31, options, listener, errHandler, rawEmitter);
13063
13063
  if (!watcher)
13064
13064
  return;
13065
13065
  return watcher.close.bind(watcher);
@@ -13070,7 +13070,7 @@ var setFsWatchListener = (path30, fullPath, options, handlers) => {
13070
13070
  addAndConvert(cont, KEY_RAW, rawEmitter);
13071
13071
  } else {
13072
13072
  watcher = createFsWatchInstance(
13073
- path30,
13073
+ path31,
13074
13074
  options,
13075
13075
  fsWatchBroadcast.bind(null, fullPath, KEY_LISTENERS),
13076
13076
  errHandler,
@@ -13085,7 +13085,7 @@ var setFsWatchListener = (path30, fullPath, options, handlers) => {
13085
13085
  cont.watcherUnusable = true;
13086
13086
  if (isWindows && error.code === "EPERM") {
13087
13087
  try {
13088
- const fd = await (0, import_promises2.open)(path30, "r");
13088
+ const fd = await (0, import_promises2.open)(path31, "r");
13089
13089
  await fd.close();
13090
13090
  broadcastErr(error);
13091
13091
  } catch (err) {
@@ -13116,7 +13116,7 @@ var setFsWatchListener = (path30, fullPath, options, handlers) => {
13116
13116
  };
13117
13117
  };
13118
13118
  var FsWatchFileInstances = /* @__PURE__ */ new Map();
13119
- var setFsWatchFileListener = (path30, fullPath, options, handlers) => {
13119
+ var setFsWatchFileListener = (path31, fullPath, options, handlers) => {
13120
13120
  const { listener, rawEmitter } = handlers;
13121
13121
  let cont = FsWatchFileInstances.get(fullPath);
13122
13122
  const copts = cont && cont.options;
@@ -13138,7 +13138,7 @@ var setFsWatchFileListener = (path30, fullPath, options, handlers) => {
13138
13138
  });
13139
13139
  const currmtime = curr.mtimeMs;
13140
13140
  if (curr.size !== prev.size || currmtime > prev.mtimeMs || currmtime === 0) {
13141
- foreach(cont.listeners, (listener2) => listener2(path30, curr));
13141
+ foreach(cont.listeners, (listener2) => listener2(path31, curr));
13142
13142
  }
13143
13143
  })
13144
13144
  };
@@ -13166,13 +13166,13 @@ var NodeFsHandler = class {
13166
13166
  * @param listener on fs change
13167
13167
  * @returns closer for the watcher instance
13168
13168
  */
13169
- _watchWithNodeFs(path30, listener) {
13169
+ _watchWithNodeFs(path31, listener) {
13170
13170
  const opts = this.fsw.options;
13171
- const directory = sysPath.dirname(path30);
13172
- const basename3 = sysPath.basename(path30);
13171
+ const directory = sysPath.dirname(path31);
13172
+ const basename3 = sysPath.basename(path31);
13173
13173
  const parent = this.fsw._getWatchedDir(directory);
13174
13174
  parent.add(basename3);
13175
- const absolutePath = sysPath.resolve(path30);
13175
+ const absolutePath = sysPath.resolve(path31);
13176
13176
  const options = {
13177
13177
  persistent: opts.persistent
13178
13178
  };
@@ -13182,12 +13182,12 @@ var NodeFsHandler = class {
13182
13182
  if (opts.usePolling) {
13183
13183
  const enableBin = opts.interval !== opts.binaryInterval;
13184
13184
  options.interval = enableBin && isBinaryPath(basename3) ? opts.binaryInterval : opts.interval;
13185
- closer = setFsWatchFileListener(path30, absolutePath, options, {
13185
+ closer = setFsWatchFileListener(path31, absolutePath, options, {
13186
13186
  listener,
13187
13187
  rawEmitter: this.fsw._emitRaw
13188
13188
  });
13189
13189
  } else {
13190
- closer = setFsWatchListener(path30, absolutePath, options, {
13190
+ closer = setFsWatchListener(path31, absolutePath, options, {
13191
13191
  listener,
13192
13192
  errHandler: this._boundHandleError,
13193
13193
  rawEmitter: this.fsw._emitRaw
@@ -13209,7 +13209,7 @@ var NodeFsHandler = class {
13209
13209
  let prevStats = stats;
13210
13210
  if (parent.has(basename3))
13211
13211
  return;
13212
- const listener = async (path30, newStats) => {
13212
+ const listener = async (path31, newStats) => {
13213
13213
  if (!this.fsw._throttle(THROTTLE_MODE_WATCH, file, 5))
13214
13214
  return;
13215
13215
  if (!newStats || newStats.mtimeMs === 0) {
@@ -13223,11 +13223,11 @@ var NodeFsHandler = class {
13223
13223
  this.fsw._emit(EV.CHANGE, file, newStats2);
13224
13224
  }
13225
13225
  if ((isMacos || isLinux || isFreeBSD) && prevStats.ino !== newStats2.ino) {
13226
- this.fsw._closeFile(path30);
13226
+ this.fsw._closeFile(path31);
13227
13227
  prevStats = newStats2;
13228
13228
  const closer2 = this._watchWithNodeFs(file, listener);
13229
13229
  if (closer2)
13230
- this.fsw._addPathCloser(path30, closer2);
13230
+ this.fsw._addPathCloser(path31, closer2);
13231
13231
  } else {
13232
13232
  prevStats = newStats2;
13233
13233
  }
@@ -13259,7 +13259,7 @@ var NodeFsHandler = class {
13259
13259
  * @param item basename of this item
13260
13260
  * @returns true if no more processing is needed for this entry.
13261
13261
  */
13262
- async _handleSymlink(entry, directory, path30, item) {
13262
+ async _handleSymlink(entry, directory, path31, item) {
13263
13263
  if (this.fsw.closed) {
13264
13264
  return;
13265
13265
  }
@@ -13269,7 +13269,7 @@ var NodeFsHandler = class {
13269
13269
  this.fsw._incrReadyCount();
13270
13270
  let linkPath;
13271
13271
  try {
13272
- linkPath = await (0, import_promises2.realpath)(path30);
13272
+ linkPath = await (0, import_promises2.realpath)(path31);
13273
13273
  } catch (e) {
13274
13274
  this.fsw._emitReady();
13275
13275
  return true;
@@ -13279,12 +13279,12 @@ var NodeFsHandler = class {
13279
13279
  if (dir.has(item)) {
13280
13280
  if (this.fsw._symlinkPaths.get(full) !== linkPath) {
13281
13281
  this.fsw._symlinkPaths.set(full, linkPath);
13282
- this.fsw._emit(EV.CHANGE, path30, entry.stats);
13282
+ this.fsw._emit(EV.CHANGE, path31, entry.stats);
13283
13283
  }
13284
13284
  } else {
13285
13285
  dir.add(item);
13286
13286
  this.fsw._symlinkPaths.set(full, linkPath);
13287
- this.fsw._emit(EV.ADD, path30, entry.stats);
13287
+ this.fsw._emit(EV.ADD, path31, entry.stats);
13288
13288
  }
13289
13289
  this.fsw._emitReady();
13290
13290
  return true;
@@ -13313,9 +13313,9 @@ var NodeFsHandler = class {
13313
13313
  return;
13314
13314
  }
13315
13315
  const item = entry.path;
13316
- let path30 = sysPath.join(directory, item);
13316
+ let path31 = sysPath.join(directory, item);
13317
13317
  current.add(item);
13318
- if (entry.stats.isSymbolicLink() && await this._handleSymlink(entry, directory, path30, item)) {
13318
+ if (entry.stats.isSymbolicLink() && await this._handleSymlink(entry, directory, path31, item)) {
13319
13319
  return;
13320
13320
  }
13321
13321
  if (this.fsw.closed) {
@@ -13324,8 +13324,8 @@ var NodeFsHandler = class {
13324
13324
  }
13325
13325
  if (item === target || !target && !previous.has(item)) {
13326
13326
  this.fsw._incrReadyCount();
13327
- path30 = sysPath.join(dir, sysPath.relative(dir, path30));
13328
- this._addToNodeFs(path30, initialAdd, wh, depth + 1);
13327
+ path31 = sysPath.join(dir, sysPath.relative(dir, path31));
13328
+ this._addToNodeFs(path31, initialAdd, wh, depth + 1);
13329
13329
  }
13330
13330
  }).on(EV.ERROR, this._boundHandleError);
13331
13331
  return new Promise((resolve3, reject) => {
@@ -13394,13 +13394,13 @@ var NodeFsHandler = class {
13394
13394
  * @param depth Child path actually targeted for watch
13395
13395
  * @param target Child path actually targeted for watch
13396
13396
  */
13397
- async _addToNodeFs(path30, initialAdd, priorWh, depth, target) {
13397
+ async _addToNodeFs(path31, initialAdd, priorWh, depth, target) {
13398
13398
  const ready = this.fsw._emitReady;
13399
- if (this.fsw._isIgnored(path30) || this.fsw.closed) {
13399
+ if (this.fsw._isIgnored(path31) || this.fsw.closed) {
13400
13400
  ready();
13401
13401
  return false;
13402
13402
  }
13403
- const wh = this.fsw._getWatchHelpers(path30);
13403
+ const wh = this.fsw._getWatchHelpers(path31);
13404
13404
  if (priorWh) {
13405
13405
  wh.filterPath = (entry) => priorWh.filterPath(entry);
13406
13406
  wh.filterDir = (entry) => priorWh.filterDir(entry);
@@ -13416,8 +13416,8 @@ var NodeFsHandler = class {
13416
13416
  const follow = this.fsw.options.followSymlinks;
13417
13417
  let closer;
13418
13418
  if (stats.isDirectory()) {
13419
- const absPath = sysPath.resolve(path30);
13420
- const targetPath = follow ? await (0, import_promises2.realpath)(path30) : path30;
13419
+ const absPath = sysPath.resolve(path31);
13420
+ const targetPath = follow ? await (0, import_promises2.realpath)(path31) : path31;
13421
13421
  if (this.fsw.closed)
13422
13422
  return;
13423
13423
  closer = await this._handleDir(wh.watchPath, stats, initialAdd, depth, target, wh, targetPath);
@@ -13427,29 +13427,29 @@ var NodeFsHandler = class {
13427
13427
  this.fsw._symlinkPaths.set(absPath, targetPath);
13428
13428
  }
13429
13429
  } else if (stats.isSymbolicLink()) {
13430
- const targetPath = follow ? await (0, import_promises2.realpath)(path30) : path30;
13430
+ const targetPath = follow ? await (0, import_promises2.realpath)(path31) : path31;
13431
13431
  if (this.fsw.closed)
13432
13432
  return;
13433
13433
  const parent = sysPath.dirname(wh.watchPath);
13434
13434
  this.fsw._getWatchedDir(parent).add(wh.watchPath);
13435
13435
  this.fsw._emit(EV.ADD, wh.watchPath, stats);
13436
- closer = await this._handleDir(parent, stats, initialAdd, depth, path30, wh, targetPath);
13436
+ closer = await this._handleDir(parent, stats, initialAdd, depth, path31, wh, targetPath);
13437
13437
  if (this.fsw.closed)
13438
13438
  return;
13439
13439
  if (targetPath !== void 0) {
13440
- this.fsw._symlinkPaths.set(sysPath.resolve(path30), targetPath);
13440
+ this.fsw._symlinkPaths.set(sysPath.resolve(path31), targetPath);
13441
13441
  }
13442
13442
  } else {
13443
13443
  closer = this._handleFile(wh.watchPath, stats, initialAdd);
13444
13444
  }
13445
13445
  ready();
13446
13446
  if (closer)
13447
- this.fsw._addPathCloser(path30, closer);
13447
+ this.fsw._addPathCloser(path31, closer);
13448
13448
  return false;
13449
13449
  } catch (error) {
13450
13450
  if (this.fsw._handleError(error)) {
13451
13451
  ready();
13452
- return path30;
13452
+ return path31;
13453
13453
  }
13454
13454
  }
13455
13455
  }
@@ -13492,26 +13492,26 @@ function createPattern(matcher) {
13492
13492
  }
13493
13493
  return () => false;
13494
13494
  }
13495
- function normalizePath(path30) {
13496
- if (typeof path30 !== "string")
13495
+ function normalizePath(path31) {
13496
+ if (typeof path31 !== "string")
13497
13497
  throw new Error("string expected");
13498
- path30 = sysPath2.normalize(path30);
13499
- path30 = path30.replace(/\\/g, "/");
13498
+ path31 = sysPath2.normalize(path31);
13499
+ path31 = path31.replace(/\\/g, "/");
13500
13500
  let prepend = false;
13501
- if (path30.startsWith("//"))
13501
+ if (path31.startsWith("//"))
13502
13502
  prepend = true;
13503
13503
  const DOUBLE_SLASH_RE2 = /\/\//;
13504
- while (path30.match(DOUBLE_SLASH_RE2))
13505
- path30 = path30.replace(DOUBLE_SLASH_RE2, "/");
13504
+ while (path31.match(DOUBLE_SLASH_RE2))
13505
+ path31 = path31.replace(DOUBLE_SLASH_RE2, "/");
13506
13506
  if (prepend)
13507
- path30 = "/" + path30;
13508
- return path30;
13507
+ path31 = "/" + path31;
13508
+ return path31;
13509
13509
  }
13510
13510
  function matchPatterns(patterns, testString, stats) {
13511
- const path30 = normalizePath(testString);
13511
+ const path31 = normalizePath(testString);
13512
13512
  for (let index = 0; index < patterns.length; index++) {
13513
13513
  const pattern = patterns[index];
13514
- if (pattern(path30, stats)) {
13514
+ if (pattern(path31, stats)) {
13515
13515
  return true;
13516
13516
  }
13517
13517
  }
@@ -13551,19 +13551,19 @@ var toUnix = (string) => {
13551
13551
  }
13552
13552
  return str;
13553
13553
  };
13554
- var normalizePathToUnix = (path30) => toUnix(sysPath2.normalize(toUnix(path30)));
13555
- var normalizeIgnored = (cwd = "") => (path30) => {
13556
- if (typeof path30 === "string") {
13557
- return normalizePathToUnix(sysPath2.isAbsolute(path30) ? path30 : sysPath2.join(cwd, path30));
13554
+ var normalizePathToUnix = (path31) => toUnix(sysPath2.normalize(toUnix(path31)));
13555
+ var normalizeIgnored = (cwd = "") => (path31) => {
13556
+ if (typeof path31 === "string") {
13557
+ return normalizePathToUnix(sysPath2.isAbsolute(path31) ? path31 : sysPath2.join(cwd, path31));
13558
13558
  } else {
13559
- return path30;
13559
+ return path31;
13560
13560
  }
13561
13561
  };
13562
- var getAbsolutePath = (path30, cwd) => {
13563
- if (sysPath2.isAbsolute(path30)) {
13564
- return path30;
13562
+ var getAbsolutePath = (path31, cwd) => {
13563
+ if (sysPath2.isAbsolute(path31)) {
13564
+ return path31;
13565
13565
  }
13566
- return sysPath2.join(cwd, path30);
13566
+ return sysPath2.join(cwd, path31);
13567
13567
  };
13568
13568
  var EMPTY_SET = Object.freeze(/* @__PURE__ */ new Set());
13569
13569
  var DirEntry = class {
@@ -13618,10 +13618,10 @@ var DirEntry = class {
13618
13618
  var STAT_METHOD_F = "stat";
13619
13619
  var STAT_METHOD_L = "lstat";
13620
13620
  var WatchHelper = class {
13621
- constructor(path30, follow, fsw) {
13621
+ constructor(path31, follow, fsw) {
13622
13622
  this.fsw = fsw;
13623
- const watchPath = path30;
13624
- this.path = path30 = path30.replace(REPLACER_RE, "");
13623
+ const watchPath = path31;
13624
+ this.path = path31 = path31.replace(REPLACER_RE, "");
13625
13625
  this.watchPath = watchPath;
13626
13626
  this.fullWatchPath = sysPath2.resolve(watchPath);
13627
13627
  this.dirParts = [];
@@ -13743,20 +13743,20 @@ var FSWatcher = class extends import_events.EventEmitter {
13743
13743
  this._closePromise = void 0;
13744
13744
  let paths = unifyPaths(paths_);
13745
13745
  if (cwd) {
13746
- paths = paths.map((path30) => {
13747
- const absPath = getAbsolutePath(path30, cwd);
13746
+ paths = paths.map((path31) => {
13747
+ const absPath = getAbsolutePath(path31, cwd);
13748
13748
  return absPath;
13749
13749
  });
13750
13750
  }
13751
- paths.forEach((path30) => {
13752
- this._removeIgnoredPath(path30);
13751
+ paths.forEach((path31) => {
13752
+ this._removeIgnoredPath(path31);
13753
13753
  });
13754
13754
  this._userIgnored = void 0;
13755
13755
  if (!this._readyCount)
13756
13756
  this._readyCount = 0;
13757
13757
  this._readyCount += paths.length;
13758
- Promise.all(paths.map(async (path30) => {
13759
- const res = await this._nodeFsHandler._addToNodeFs(path30, !_internal, void 0, 0, _origAdd);
13758
+ Promise.all(paths.map(async (path31) => {
13759
+ const res = await this._nodeFsHandler._addToNodeFs(path31, !_internal, void 0, 0, _origAdd);
13760
13760
  if (res)
13761
13761
  this._emitReady();
13762
13762
  return res;
@@ -13778,17 +13778,17 @@ var FSWatcher = class extends import_events.EventEmitter {
13778
13778
  return this;
13779
13779
  const paths = unifyPaths(paths_);
13780
13780
  const { cwd } = this.options;
13781
- paths.forEach((path30) => {
13782
- if (!sysPath2.isAbsolute(path30) && !this._closers.has(path30)) {
13781
+ paths.forEach((path31) => {
13782
+ if (!sysPath2.isAbsolute(path31) && !this._closers.has(path31)) {
13783
13783
  if (cwd)
13784
- path30 = sysPath2.join(cwd, path30);
13785
- path30 = sysPath2.resolve(path30);
13784
+ path31 = sysPath2.join(cwd, path31);
13785
+ path31 = sysPath2.resolve(path31);
13786
13786
  }
13787
- this._closePath(path30);
13788
- this._addIgnoredPath(path30);
13789
- if (this._watched.has(path30)) {
13787
+ this._closePath(path31);
13788
+ this._addIgnoredPath(path31);
13789
+ if (this._watched.has(path31)) {
13790
13790
  this._addIgnoredPath({
13791
- path: path30,
13791
+ path: path31,
13792
13792
  recursive: true
13793
13793
  });
13794
13794
  }
@@ -13852,38 +13852,38 @@ var FSWatcher = class extends import_events.EventEmitter {
13852
13852
  * @param stats arguments to be passed with event
13853
13853
  * @returns the error if defined, otherwise the value of the FSWatcher instance's `closed` flag
13854
13854
  */
13855
- async _emit(event, path30, stats) {
13855
+ async _emit(event, path31, stats) {
13856
13856
  if (this.closed)
13857
13857
  return;
13858
13858
  const opts = this.options;
13859
13859
  if (isWindows)
13860
- path30 = sysPath2.normalize(path30);
13860
+ path31 = sysPath2.normalize(path31);
13861
13861
  if (opts.cwd)
13862
- path30 = sysPath2.relative(opts.cwd, path30);
13863
- const args = [path30];
13862
+ path31 = sysPath2.relative(opts.cwd, path31);
13863
+ const args = [path31];
13864
13864
  if (stats != null)
13865
13865
  args.push(stats);
13866
13866
  const awf = opts.awaitWriteFinish;
13867
13867
  let pw;
13868
- if (awf && (pw = this._pendingWrites.get(path30))) {
13868
+ if (awf && (pw = this._pendingWrites.get(path31))) {
13869
13869
  pw.lastChange = /* @__PURE__ */ new Date();
13870
13870
  return this;
13871
13871
  }
13872
13872
  if (opts.atomic) {
13873
13873
  if (event === EVENTS.UNLINK) {
13874
- this._pendingUnlinks.set(path30, [event, ...args]);
13874
+ this._pendingUnlinks.set(path31, [event, ...args]);
13875
13875
  setTimeout(() => {
13876
- this._pendingUnlinks.forEach((entry, path31) => {
13876
+ this._pendingUnlinks.forEach((entry, path32) => {
13877
13877
  this.emit(...entry);
13878
13878
  this.emit(EVENTS.ALL, ...entry);
13879
- this._pendingUnlinks.delete(path31);
13879
+ this._pendingUnlinks.delete(path32);
13880
13880
  });
13881
13881
  }, typeof opts.atomic === "number" ? opts.atomic : 100);
13882
13882
  return this;
13883
13883
  }
13884
- if (event === EVENTS.ADD && this._pendingUnlinks.has(path30)) {
13884
+ if (event === EVENTS.ADD && this._pendingUnlinks.has(path31)) {
13885
13885
  event = EVENTS.CHANGE;
13886
- this._pendingUnlinks.delete(path30);
13886
+ this._pendingUnlinks.delete(path31);
13887
13887
  }
13888
13888
  }
13889
13889
  if (awf && (event === EVENTS.ADD || event === EVENTS.CHANGE) && this._readyEmitted) {
@@ -13901,16 +13901,16 @@ var FSWatcher = class extends import_events.EventEmitter {
13901
13901
  this.emitWithAll(event, args);
13902
13902
  }
13903
13903
  };
13904
- this._awaitWriteFinish(path30, awf.stabilityThreshold, event, awfEmit);
13904
+ this._awaitWriteFinish(path31, awf.stabilityThreshold, event, awfEmit);
13905
13905
  return this;
13906
13906
  }
13907
13907
  if (event === EVENTS.CHANGE) {
13908
- const isThrottled = !this._throttle(EVENTS.CHANGE, path30, 50);
13908
+ const isThrottled = !this._throttle(EVENTS.CHANGE, path31, 50);
13909
13909
  if (isThrottled)
13910
13910
  return this;
13911
13911
  }
13912
13912
  if (opts.alwaysStat && stats === void 0 && (event === EVENTS.ADD || event === EVENTS.ADD_DIR || event === EVENTS.CHANGE)) {
13913
- const fullPath = opts.cwd ? sysPath2.join(opts.cwd, path30) : path30;
13913
+ const fullPath = opts.cwd ? sysPath2.join(opts.cwd, path31) : path31;
13914
13914
  let stats2;
13915
13915
  try {
13916
13916
  stats2 = await (0, import_promises3.stat)(fullPath);
@@ -13941,23 +13941,23 @@ var FSWatcher = class extends import_events.EventEmitter {
13941
13941
  * @param timeout duration of time to suppress duplicate actions
13942
13942
  * @returns tracking object or false if action should be suppressed
13943
13943
  */
13944
- _throttle(actionType, path30, timeout) {
13944
+ _throttle(actionType, path31, timeout) {
13945
13945
  if (!this._throttled.has(actionType)) {
13946
13946
  this._throttled.set(actionType, /* @__PURE__ */ new Map());
13947
13947
  }
13948
13948
  const action = this._throttled.get(actionType);
13949
13949
  if (!action)
13950
13950
  throw new Error("invalid throttle");
13951
- const actionPath = action.get(path30);
13951
+ const actionPath = action.get(path31);
13952
13952
  if (actionPath) {
13953
13953
  actionPath.count++;
13954
13954
  return false;
13955
13955
  }
13956
13956
  let timeoutObject;
13957
13957
  const clear = () => {
13958
- const item = action.get(path30);
13958
+ const item = action.get(path31);
13959
13959
  const count = item ? item.count : 0;
13960
- action.delete(path30);
13960
+ action.delete(path31);
13961
13961
  clearTimeout(timeoutObject);
13962
13962
  if (item)
13963
13963
  clearTimeout(item.timeoutObject);
@@ -13965,7 +13965,7 @@ var FSWatcher = class extends import_events.EventEmitter {
13965
13965
  };
13966
13966
  timeoutObject = setTimeout(clear, timeout);
13967
13967
  const thr = { timeoutObject, clear, count: 0 };
13968
- action.set(path30, thr);
13968
+ action.set(path31, thr);
13969
13969
  return thr;
13970
13970
  }
13971
13971
  _incrReadyCount() {
@@ -13979,44 +13979,44 @@ var FSWatcher = class extends import_events.EventEmitter {
13979
13979
  * @param event
13980
13980
  * @param awfEmit Callback to be called when ready for event to be emitted.
13981
13981
  */
13982
- _awaitWriteFinish(path30, threshold, event, awfEmit) {
13982
+ _awaitWriteFinish(path31, threshold, event, awfEmit) {
13983
13983
  const awf = this.options.awaitWriteFinish;
13984
13984
  if (typeof awf !== "object")
13985
13985
  return;
13986
13986
  const pollInterval = awf.pollInterval;
13987
13987
  let timeoutHandler;
13988
- let fullPath = path30;
13989
- if (this.options.cwd && !sysPath2.isAbsolute(path30)) {
13990
- fullPath = sysPath2.join(this.options.cwd, path30);
13988
+ let fullPath = path31;
13989
+ if (this.options.cwd && !sysPath2.isAbsolute(path31)) {
13990
+ fullPath = sysPath2.join(this.options.cwd, path31);
13991
13991
  }
13992
13992
  const now = /* @__PURE__ */ new Date();
13993
13993
  const writes = this._pendingWrites;
13994
13994
  function awaitWriteFinishFn(prevStat) {
13995
13995
  (0, import_fs17.stat)(fullPath, (err, curStat) => {
13996
- if (err || !writes.has(path30)) {
13996
+ if (err || !writes.has(path31)) {
13997
13997
  if (err && err.code !== "ENOENT")
13998
13998
  awfEmit(err);
13999
13999
  return;
14000
14000
  }
14001
14001
  const now2 = Number(/* @__PURE__ */ new Date());
14002
14002
  if (prevStat && curStat.size !== prevStat.size) {
14003
- writes.get(path30).lastChange = now2;
14003
+ writes.get(path31).lastChange = now2;
14004
14004
  }
14005
- const pw = writes.get(path30);
14005
+ const pw = writes.get(path31);
14006
14006
  const df = now2 - pw.lastChange;
14007
14007
  if (df >= threshold) {
14008
- writes.delete(path30);
14008
+ writes.delete(path31);
14009
14009
  awfEmit(void 0, curStat);
14010
14010
  } else {
14011
14011
  timeoutHandler = setTimeout(awaitWriteFinishFn, pollInterval, curStat);
14012
14012
  }
14013
14013
  });
14014
14014
  }
14015
- if (!writes.has(path30)) {
14016
- writes.set(path30, {
14015
+ if (!writes.has(path31)) {
14016
+ writes.set(path31, {
14017
14017
  lastChange: now,
14018
14018
  cancelWait: () => {
14019
- writes.delete(path30);
14019
+ writes.delete(path31);
14020
14020
  clearTimeout(timeoutHandler);
14021
14021
  return event;
14022
14022
  }
@@ -14027,8 +14027,8 @@ var FSWatcher = class extends import_events.EventEmitter {
14027
14027
  /**
14028
14028
  * Determines whether user has asked to ignore this path.
14029
14029
  */
14030
- _isIgnored(path30, stats) {
14031
- if (this.options.atomic && DOT_RE.test(path30))
14030
+ _isIgnored(path31, stats) {
14031
+ if (this.options.atomic && DOT_RE.test(path31))
14032
14032
  return true;
14033
14033
  if (!this._userIgnored) {
14034
14034
  const { cwd } = this.options;
@@ -14038,17 +14038,17 @@ var FSWatcher = class extends import_events.EventEmitter {
14038
14038
  const list = [...ignoredPaths.map(normalizeIgnored(cwd)), ...ignored];
14039
14039
  this._userIgnored = anymatch(list, void 0);
14040
14040
  }
14041
- return this._userIgnored(path30, stats);
14041
+ return this._userIgnored(path31, stats);
14042
14042
  }
14043
- _isntIgnored(path30, stat4) {
14044
- return !this._isIgnored(path30, stat4);
14043
+ _isntIgnored(path31, stat4) {
14044
+ return !this._isIgnored(path31, stat4);
14045
14045
  }
14046
14046
  /**
14047
14047
  * Provides a set of common helpers and properties relating to symlink handling.
14048
14048
  * @param path file or directory pattern being watched
14049
14049
  */
14050
- _getWatchHelpers(path30) {
14051
- return new WatchHelper(path30, this.options.followSymlinks, this);
14050
+ _getWatchHelpers(path31) {
14051
+ return new WatchHelper(path31, this.options.followSymlinks, this);
14052
14052
  }
14053
14053
  // Directory helpers
14054
14054
  // -----------------
@@ -14080,63 +14080,63 @@ var FSWatcher = class extends import_events.EventEmitter {
14080
14080
  * @param item base path of item/directory
14081
14081
  */
14082
14082
  _remove(directory, item, isDirectory) {
14083
- const path30 = sysPath2.join(directory, item);
14084
- const fullPath = sysPath2.resolve(path30);
14085
- isDirectory = isDirectory != null ? isDirectory : this._watched.has(path30) || this._watched.has(fullPath);
14086
- if (!this._throttle("remove", path30, 100))
14083
+ const path31 = sysPath2.join(directory, item);
14084
+ const fullPath = sysPath2.resolve(path31);
14085
+ isDirectory = isDirectory != null ? isDirectory : this._watched.has(path31) || this._watched.has(fullPath);
14086
+ if (!this._throttle("remove", path31, 100))
14087
14087
  return;
14088
14088
  if (!isDirectory && this._watched.size === 1) {
14089
14089
  this.add(directory, item, true);
14090
14090
  }
14091
- const wp = this._getWatchedDir(path30);
14091
+ const wp = this._getWatchedDir(path31);
14092
14092
  const nestedDirectoryChildren = wp.getChildren();
14093
- nestedDirectoryChildren.forEach((nested) => this._remove(path30, nested));
14093
+ nestedDirectoryChildren.forEach((nested) => this._remove(path31, nested));
14094
14094
  const parent = this._getWatchedDir(directory);
14095
14095
  const wasTracked = parent.has(item);
14096
14096
  parent.remove(item);
14097
14097
  if (this._symlinkPaths.has(fullPath)) {
14098
14098
  this._symlinkPaths.delete(fullPath);
14099
14099
  }
14100
- let relPath = path30;
14100
+ let relPath = path31;
14101
14101
  if (this.options.cwd)
14102
- relPath = sysPath2.relative(this.options.cwd, path30);
14102
+ relPath = sysPath2.relative(this.options.cwd, path31);
14103
14103
  if (this.options.awaitWriteFinish && this._pendingWrites.has(relPath)) {
14104
14104
  const event = this._pendingWrites.get(relPath).cancelWait();
14105
14105
  if (event === EVENTS.ADD)
14106
14106
  return;
14107
14107
  }
14108
- this._watched.delete(path30);
14108
+ this._watched.delete(path31);
14109
14109
  this._watched.delete(fullPath);
14110
14110
  const eventName = isDirectory ? EVENTS.UNLINK_DIR : EVENTS.UNLINK;
14111
- if (wasTracked && !this._isIgnored(path30))
14112
- this._emit(eventName, path30);
14113
- this._closePath(path30);
14111
+ if (wasTracked && !this._isIgnored(path31))
14112
+ this._emit(eventName, path31);
14113
+ this._closePath(path31);
14114
14114
  }
14115
14115
  /**
14116
14116
  * Closes all watchers for a path
14117
14117
  */
14118
- _closePath(path30) {
14119
- this._closeFile(path30);
14120
- const dir = sysPath2.dirname(path30);
14121
- this._getWatchedDir(dir).remove(sysPath2.basename(path30));
14118
+ _closePath(path31) {
14119
+ this._closeFile(path31);
14120
+ const dir = sysPath2.dirname(path31);
14121
+ this._getWatchedDir(dir).remove(sysPath2.basename(path31));
14122
14122
  }
14123
14123
  /**
14124
14124
  * Closes only file-specific watchers
14125
14125
  */
14126
- _closeFile(path30) {
14127
- const closers = this._closers.get(path30);
14126
+ _closeFile(path31) {
14127
+ const closers = this._closers.get(path31);
14128
14128
  if (!closers)
14129
14129
  return;
14130
14130
  closers.forEach((closer) => closer());
14131
- this._closers.delete(path30);
14131
+ this._closers.delete(path31);
14132
14132
  }
14133
- _addPathCloser(path30, closer) {
14133
+ _addPathCloser(path31, closer) {
14134
14134
  if (!closer)
14135
14135
  return;
14136
- let list = this._closers.get(path30);
14136
+ let list = this._closers.get(path31);
14137
14137
  if (!list) {
14138
14138
  list = [];
14139
- this._closers.set(path30, list);
14139
+ this._closers.set(path31, list);
14140
14140
  }
14141
14141
  list.push(closer);
14142
14142
  }
@@ -14822,12 +14822,12 @@ var DEFAULT_IGNORED_PATHS = [
14822
14822
  /^\/sockjs-node/
14823
14823
  // Hot reload websocket
14824
14824
  ];
14825
- function shouldIgnorePath(path30, ignoredPaths) {
14825
+ function shouldIgnorePath(path31, ignoredPaths) {
14826
14826
  return ignoredPaths.some((pattern) => {
14827
14827
  if (typeof pattern === "string") {
14828
- return path30 === pattern || path30.startsWith(pattern);
14828
+ return path31 === pattern || path31.startsWith(pattern);
14829
14829
  }
14830
- return pattern.test(path30);
14830
+ return pattern.test(path31);
14831
14831
  });
14832
14832
  }
14833
14833
  function requestLoggerMiddleware(options = {}) {
@@ -14986,11 +14986,11 @@ function createStrictRateLimiterFromConfig(config) {
14986
14986
  }
14987
14987
 
14988
14988
  // modules/server/middleware/auto-rate-limit.ts
14989
- function matchesStrictPattern(path30, patterns) {
14989
+ function matchesStrictPattern(path31, patterns) {
14990
14990
  for (const pattern of patterns) {
14991
14991
  const regexPattern = pattern.replace(/\*\*/g, ".*").replace(/\*/g, "[^/]*").replace(/\//g, "\\/");
14992
14992
  const regex = new RegExp(`^${regexPattern}$`);
14993
- if (regex.test(path30)) {
14993
+ if (regex.test(path31)) {
14994
14994
  return true;
14995
14995
  }
14996
14996
  }
@@ -15026,6 +15026,7 @@ function getAutoRateLimiter(route, strictPatterns = [], rateLimitConfig) {
15026
15026
  // modules/server/handlers/api.ts
15027
15027
  async function handleApiRequest(options) {
15028
15028
  const { apiRoutes, urlPath, req, res, env = "dev", rewriteLoader } = options;
15029
+ const originalUrlPath = urlPath;
15029
15030
  let finalUrlPath = urlPath;
15030
15031
  let extractedParams = {};
15031
15032
  if (rewriteLoader) {
@@ -15064,6 +15065,33 @@ async function handleApiRequest(options) {
15064
15065
  }
15065
15066
  const sanitizedParams = sanitizeParams(params);
15066
15067
  const sanitizedQuery = sanitizeQuery(req.query);
15068
+ function reconstructPathFromParams(routePattern, params2) {
15069
+ let reconstructed = routePattern;
15070
+ for (const [key, value] of Object.entries(params2)) {
15071
+ const catchAllPattern = `[...${key}]`;
15072
+ if (reconstructed.includes(catchAllPattern)) {
15073
+ reconstructed = reconstructed.replace(catchAllPattern, value);
15074
+ } else {
15075
+ const normalPattern = `[${key}]`;
15076
+ if (reconstructed.includes(normalPattern)) {
15077
+ reconstructed = reconstructed.replace(normalPattern, value);
15078
+ }
15079
+ }
15080
+ }
15081
+ return reconstructed;
15082
+ }
15083
+ const reconstructedPath = reconstructPathFromParams(route.pattern, sanitizedParams);
15084
+ const queryString = req.url?.includes("?") ? req.url.split("?")[1] : "";
15085
+ const originalUrl = queryString ? `${reconstructedPath}?${queryString}` : reconstructedPath;
15086
+ if (!req.originalUrl) {
15087
+ req.originalUrl = originalUrl;
15088
+ }
15089
+ if (!req.params) {
15090
+ req.params = {};
15091
+ }
15092
+ for (const [key, value] of Object.entries(sanitizedParams)) {
15093
+ req.params[key] = value;
15094
+ }
15067
15095
  const ctx = {
15068
15096
  req,
15069
15097
  res,
@@ -15689,25 +15717,89 @@ function handleNotFound(res, urlPath) {
15689
15717
  }
15690
15718
  }
15691
15719
 
15692
- // modules/server/handlers/ssg.ts
15693
- var import_fs20 = __toESM(require("fs"));
15720
+ // modules/server/global-middleware.ts
15694
15721
  var import_path24 = __toESM(require("path"));
15722
+ var import_fs20 = __toESM(require("fs"));
15723
+ var cachedGlobalMiddlewares = null;
15724
+ async function loadGlobalMiddlewares(projectRoot) {
15725
+ if (cachedGlobalMiddlewares !== null) {
15726
+ return cachedGlobalMiddlewares;
15727
+ }
15728
+ const globalMiddlewareFile = import_path24.default.join(projectRoot, "global.middleware.ts");
15729
+ const globalMiddlewareFileJs = import_path24.default.join(projectRoot, "global.middleware.js");
15730
+ const file = import_fs20.default.existsSync(globalMiddlewareFile) ? globalMiddlewareFile : import_fs20.default.existsSync(globalMiddlewareFileJs) ? globalMiddlewareFileJs : null;
15731
+ if (!file) {
15732
+ cachedGlobalMiddlewares = [];
15733
+ return cachedGlobalMiddlewares;
15734
+ }
15735
+ if (file.endsWith(".ts") || file.endsWith(".tsx")) {
15736
+ try {
15737
+ require("tsx/cjs");
15738
+ } catch (e) {
15739
+ }
15740
+ }
15741
+ try {
15742
+ const mod = require(file);
15743
+ const middlewares = mod?.globalMiddlewares;
15744
+ if (Array.isArray(middlewares)) {
15745
+ const validMiddlewares = [];
15746
+ for (let i = 0; i < middlewares.length; i++) {
15747
+ const mw = middlewares[i];
15748
+ if (typeof mw === "function") {
15749
+ validMiddlewares.push(mw);
15750
+ } else {
15751
+ console.warn(
15752
+ `[framework][global-middleware] Middleware at index ${i} in global.middleware.ts is not a function, skipping`
15753
+ );
15754
+ }
15755
+ }
15756
+ cachedGlobalMiddlewares = validMiddlewares;
15757
+ return cachedGlobalMiddlewares;
15758
+ } else if (middlewares !== void 0) {
15759
+ console.warn(
15760
+ "[framework][global-middleware] globalMiddlewares must be an array in global.middleware.ts, ignoring invalid value"
15761
+ );
15762
+ }
15763
+ } catch (error) {
15764
+ console.error("[framework][global-middleware] Error loading global.middleware.ts:", error);
15765
+ }
15766
+ cachedGlobalMiddlewares = [];
15767
+ return cachedGlobalMiddlewares;
15768
+ }
15769
+ async function runGlobalMiddlewares(ctx, globalMiddlewares) {
15770
+ for (const mw of globalMiddlewares) {
15771
+ try {
15772
+ await Promise.resolve(mw(ctx, async () => {
15773
+ }));
15774
+ } catch (error) {
15775
+ console.error("[framework][global-middleware] Error in global middleware:", error);
15776
+ continue;
15777
+ }
15778
+ if (ctx.res.headersSent) {
15779
+ return;
15780
+ }
15781
+ }
15782
+ }
15783
+
15784
+ // modules/server/handlers/ssg.ts
15785
+ var import_fs21 = __toESM(require("fs"));
15786
+ var import_path25 = __toESM(require("path"));
15695
15787
  var logger3 = createModuleLogger("ssg");
15696
15788
  function getSsgDirForPath(baseDir, urlPath) {
15697
15789
  const clean = urlPath === "/" ? "" : urlPath.replace(/^\/+/, "");
15698
- return import_path24.default.join(baseDir, clean);
15790
+ return import_path25.default.join(baseDir, clean);
15699
15791
  }
15700
15792
  function getSsgHtmlPath(baseDir, urlPath) {
15701
15793
  const dir = getSsgDirForPath(baseDir, urlPath);
15702
- return import_path24.default.join(dir, "index.html");
15794
+ return import_path25.default.join(dir, "index.html");
15703
15795
  }
15704
15796
  function getSsgDataPath(baseDir, urlPath) {
15705
15797
  const dir = getSsgDirForPath(baseDir, urlPath);
15706
- return import_path24.default.join(dir, "data.json");
15798
+ return import_path25.default.join(dir, "data.json");
15707
15799
  }
15708
15800
  function tryServeSsgHtml(res, ssgOutDir, urlPath) {
15709
15801
  const ssgHtmlPath = getSsgHtmlPath(ssgOutDir, urlPath);
15710
- if (!import_fs20.default.existsSync(ssgHtmlPath)) {
15802
+ if (!import_fs21.default.existsSync(ssgHtmlPath)) {
15711
15803
  return false;
15712
15804
  }
15713
15805
  logger3.info("Serving SSG HTML", { urlPath, ssgHtmlPath });
@@ -15717,17 +15809,17 @@ function tryServeSsgHtml(res, ssgOutDir, urlPath) {
15717
15809
  );
15718
15810
  res.statusCode = 200;
15719
15811
  res.setHeader("Content-Type", "text/html; charset=utf-8");
15720
- const stream = import_fs20.default.createReadStream(ssgHtmlPath, { encoding: "utf-8" });
15812
+ const stream = import_fs21.default.createReadStream(ssgHtmlPath, { encoding: "utf-8" });
15721
15813
  stream.pipe(res);
15722
15814
  return true;
15723
15815
  }
15724
15816
  function tryServeSsgData(res, ssgOutDir, urlPath) {
15725
15817
  const ssgDataPath = getSsgDataPath(ssgOutDir, urlPath);
15726
- if (!import_fs20.default.existsSync(ssgDataPath)) {
15818
+ if (!import_fs21.default.existsSync(ssgDataPath)) {
15727
15819
  return false;
15728
15820
  }
15729
15821
  try {
15730
- const raw = import_fs20.default.readFileSync(ssgDataPath, "utf-8");
15822
+ const raw = import_fs21.default.readFileSync(ssgDataPath, "utf-8");
15731
15823
  res.setHeader("Content-Type", "application/json; charset=utf-8");
15732
15824
  res.status(200).end(raw);
15733
15825
  return true;
@@ -15739,7 +15831,7 @@ function tryServeSsgData(res, ssgOutDir, urlPath) {
15739
15831
 
15740
15832
  // modules/server/handlers/pages.ts
15741
15833
  init_globals();
15742
- var import_path25 = __toESM(require("path"));
15834
+ var import_path26 = __toESM(require("path"));
15743
15835
  function mergeMetadata(base, override) {
15744
15836
  if (!base && !override) return null;
15745
15837
  if (!base) return override;
@@ -15797,7 +15889,7 @@ async function renderNotFoundPage(notFoundPage, req, res, urlPath, finalUrlPath,
15797
15889
  } catch (error) {
15798
15890
  const reqLogger = getRequestLogger(req);
15799
15891
  const layoutFile = notFoundPage.layoutFiles[i];
15800
- const relativeLayoutPath = layoutFile ? import_path25.default.relative(projectRoot || process.cwd(), layoutFile) : "unknown";
15892
+ const relativeLayoutPath = layoutFile ? import_path26.default.relative(projectRoot || process.cwd(), layoutFile) : "unknown";
15801
15893
  reqLogger.error("Layout middleware failed for not-found page", error instanceof Error ? error : new Error(String(error)), {
15802
15894
  layoutIndex: i,
15803
15895
  layoutFile: relativeLayoutPath
@@ -15826,7 +15918,7 @@ async function renderNotFoundPage(notFoundPage, req, res, urlPath, finalUrlPath,
15826
15918
  } catch (error) {
15827
15919
  const reqLogger = getRequestLogger(req);
15828
15920
  const layoutFile = notFoundPage.layoutFiles[i];
15829
- const relativeLayoutPath = layoutFile ? import_path25.default.relative(projectRoot || process.cwd(), layoutFile) : "unknown";
15921
+ const relativeLayoutPath = layoutFile ? import_path26.default.relative(projectRoot || process.cwd(), layoutFile) : "unknown";
15830
15922
  reqLogger.warn("Layout server hook failed for not-found page", {
15831
15923
  error: error instanceof Error ? error.message : String(error),
15832
15924
  stack: error instanceof Error ? error.stack : void 0,
@@ -16063,6 +16155,11 @@ async function handlePageRequestInternal(options) {
16063
16155
  Redirect: (destination, permanent = false) => new RedirectResponse(destination, permanent),
16064
16156
  NotFound: () => new NotFoundResponse()
16065
16157
  };
16158
+ const globalMiddlewares = await loadGlobalMiddlewares(projectRoot || process.cwd());
16159
+ await runGlobalMiddlewares(ctx, globalMiddlewares);
16160
+ if (res.headersSent) {
16161
+ return;
16162
+ }
16066
16163
  await runRouteMiddlewares(route, ctx);
16067
16164
  if (res.headersSent) {
16068
16165
  return;
@@ -16083,7 +16180,7 @@ async function handlePageRequestInternal(options) {
16083
16180
  );
16084
16181
  } catch (error) {
16085
16182
  const layoutFile = route.layoutFiles[i];
16086
- const relativeLayoutPath = layoutFile ? import_path25.default.relative(projectRoot || process.cwd(), layoutFile) : "unknown";
16183
+ const relativeLayoutPath = layoutFile ? import_path26.default.relative(projectRoot || process.cwd(), layoutFile) : "unknown";
16087
16184
  reqLogger.error("Layout middleware failed", error instanceof Error ? error : new Error(String(error)), {
16088
16185
  route: route.pattern,
16089
16186
  layoutIndex: i,
@@ -16149,7 +16246,7 @@ async function handlePageRequestInternal(options) {
16149
16246
  }
16150
16247
  } catch (error) {
16151
16248
  const layoutFile = route.layoutFiles[i];
16152
- const relativeLayoutPath = layoutFile ? import_path25.default.relative(projectRoot || process.cwd(), layoutFile) : "unknown";
16249
+ const relativeLayoutPath = layoutFile ? import_path26.default.relative(projectRoot || process.cwd(), layoutFile) : "unknown";
16153
16250
  reqLogger.warn("Layout server hook failed", {
16154
16251
  error: error instanceof Error ? error.message : String(error),
16155
16252
  stack: error instanceof Error ? error.stack : void 0,
@@ -16212,7 +16309,7 @@ async function handlePageRequestInternal(options) {
16212
16309
  pageLoaderResult2.theme = theme;
16213
16310
  }
16214
16311
  } catch (error) {
16215
- const relativePagePath = route.pageFile ? import_path25.default.relative(projectRoot || process.cwd(), route.pageFile) : "unknown";
16312
+ const relativePagePath = route.pageFile ? import_path26.default.relative(projectRoot || process.cwd(), route.pageFile) : "unknown";
16216
16313
  reqLogger.error("Page server hook failed", {
16217
16314
  error: error instanceof Error ? error.message : String(error),
16218
16315
  stack: error instanceof Error ? error.stack : void 0,
@@ -16382,7 +16479,7 @@ async function renderErrorPageWithStream(errorPage, req, res, error, routeChunks
16382
16479
  );
16383
16480
  } catch (error2) {
16384
16481
  const layoutFile = errorPage.layoutFiles[i];
16385
- const relativeLayoutPath = layoutFile ? import_path25.default.relative(projectRoot || process.cwd(), layoutFile) : "unknown";
16482
+ const relativeLayoutPath = layoutFile ? import_path26.default.relative(projectRoot || process.cwd(), layoutFile) : "unknown";
16386
16483
  reqLogger.error("Layout middleware failed for error page", error2 instanceof Error ? error2 : new Error(String(error2)), {
16387
16484
  layoutIndex: i,
16388
16485
  layoutFile: relativeLayoutPath
@@ -16422,7 +16519,7 @@ async function renderErrorPageWithStream(errorPage, req, res, error, routeChunks
16422
16519
  }
16423
16520
  } catch (err) {
16424
16521
  const layoutFile = errorPage.layoutFiles[i];
16425
- const relativeLayoutPath = layoutFile ? import_path25.default.relative(projectRoot || process.cwd(), layoutFile) : "unknown";
16522
+ const relativeLayoutPath = layoutFile ? import_path26.default.relative(projectRoot || process.cwd(), layoutFile) : "unknown";
16426
16523
  reqLogger.warn("Layout server hook failed for error page", {
16427
16524
  error: err instanceof Error ? err.message : String(err),
16428
16525
  stack: err instanceof Error ? err.stack : void 0,
@@ -16745,7 +16842,7 @@ function validateRealtimeConfig(config) {
16745
16842
  }
16746
16843
 
16747
16844
  // modules/server/routes.ts
16748
- var import_path26 = __toESM(require("path"));
16845
+ var import_path27 = __toESM(require("path"));
16749
16846
  var cachedRewriteLoader = null;
16750
16847
  var cachedProjectRoot = null;
16751
16848
  var cachedIsDev = null;
@@ -16773,8 +16870,8 @@ function setupRoutes(options) {
16773
16870
  } = options;
16774
16871
  const routeChunks = routeLoader.loadRouteChunks();
16775
16872
  const rewriteLoader = getRewriteLoader(projectRoot, isDev);
16776
- const ssgOutDir = import_path26.default.join(
16777
- config ? getBuildDir(projectRoot, config) : import_path26.default.join(projectRoot, BUILD_FOLDER_NAME),
16873
+ const ssgOutDir = import_path27.default.join(
16874
+ config ? getBuildDir(projectRoot, config) : import_path27.default.join(projectRoot, BUILD_FOLDER_NAME),
16778
16875
  "ssg"
16779
16876
  );
16780
16877
  app.all("/api/*", async (req, res) => {
@@ -18003,8 +18100,8 @@ var setupApplication = async ({
18003
18100
 
18004
18101
  // src/server.ts
18005
18102
  var import_dotenv2 = __toESM(require("dotenv"));
18006
- var envPath = import_path27.default.join(process.cwd(), ".env");
18007
- if (import_fs21.default.existsSync(envPath)) {
18103
+ var envPath = import_path28.default.join(process.cwd(), ".env");
18104
+ if (import_fs22.default.existsSync(envPath)) {
18008
18105
  import_dotenv2.default.config({ path: envPath });
18009
18106
  } else {
18010
18107
  import_dotenv2.default.config();
@@ -18025,8 +18122,8 @@ async function startServer(options = {}) {
18025
18122
  }
18026
18123
  const port = options.port ?? (process.env.PORT ? parseInt(process.env.PORT, 10) : void 0) ?? config.server.port;
18027
18124
  const host = process.env.HOST ?? (!isDev ? "0.0.0.0" : void 0) ?? config.server.host;
18028
- const appDir = options.appDir ?? (isDev ? getAppDir(projectRoot, config) : import_path27.default.join(getBuildDir(projectRoot, config), "server"));
18029
- if (!isDev && !import_fs21.default.existsSync(appDir)) {
18125
+ const appDir = options.appDir ?? (isDev ? getAppDir(projectRoot, config) : import_path28.default.join(getBuildDir(projectRoot, config), "server"));
18126
+ if (!isDev && !import_fs22.default.existsSync(appDir)) {
18030
18127
  logger4.error("Compiled directory not found", void 0, {
18031
18128
  buildDir: config.directories.build,
18032
18129
  appDir,
@@ -18097,10 +18194,10 @@ async function startProdServer(options = {}) {
18097
18194
  }
18098
18195
 
18099
18196
  // modules/build/ssg/builder.ts
18100
- var import_path31 = __toESM(require("path"));
18197
+ var import_path32 = __toESM(require("path"));
18101
18198
 
18102
18199
  // modules/build/ssg/path.ts
18103
- var import_path28 = __toESM(require("path"));
18200
+ var import_path29 = __toESM(require("path"));
18104
18201
  function buildPathFromPattern(pattern, params) {
18105
18202
  const segments = pattern.split("/").filter(Boolean);
18106
18203
  const parts = [];
@@ -18129,12 +18226,12 @@ function buildPathFromPattern(pattern, params) {
18129
18226
  }
18130
18227
  function pathToOutDir(baseDir, urlPath) {
18131
18228
  const clean = urlPath === "/" ? "" : urlPath.replace(/^\/+/, "");
18132
- return import_path28.default.join(baseDir, clean);
18229
+ return import_path29.default.join(baseDir, clean);
18133
18230
  }
18134
18231
 
18135
18232
  // modules/build/ssg/renderer.ts
18136
- var import_fs22 = __toESM(require("fs"));
18137
- var import_path29 = __toESM(require("path"));
18233
+ var import_fs23 = __toESM(require("fs"));
18234
+ var import_path30 = __toESM(require("path"));
18138
18235
  var import_server3 = require("react-dom/server");
18139
18236
  init_globals();
18140
18237
  async function renderStaticRoute(projectRoot, ssgOutDir, route, urlPath, params, config) {
@@ -18270,16 +18367,16 @@ async function renderStaticRoute(projectRoot, ssgOutDir, route, urlPath, params,
18270
18367
  const html = "<!DOCTYPE html>" + (0, import_server3.renderToString)(documentTree);
18271
18368
  const dir = pathToOutDir(ssgOutDir, urlPath);
18272
18369
  ensureDir(dir);
18273
- const htmlFile = import_path29.default.join(dir, "index.html");
18274
- const dataFile = import_path29.default.join(dir, "data.json");
18275
- import_fs22.default.writeFileSync(htmlFile, html, "utf-8");
18276
- import_fs22.default.writeFileSync(dataFile, JSON.stringify(initialData, null, 2), "utf-8");
18370
+ const htmlFile = import_path30.default.join(dir, "index.html");
18371
+ const dataFile = import_path30.default.join(dir, "data.json");
18372
+ import_fs23.default.writeFileSync(htmlFile, html, "utf-8");
18373
+ import_fs23.default.writeFileSync(dataFile, JSON.stringify(initialData, null, 2), "utf-8");
18277
18374
  }
18278
18375
 
18279
18376
  // modules/build/ssg/builder.ts
18280
18377
  init_globals();
18281
18378
  async function buildStaticPages(projectRoot, routes, config) {
18282
- const ssgOutDir = import_path31.default.join(projectRoot, BUILD_FOLDER_NAME, "ssg");
18379
+ const ssgOutDir = import_path32.default.join(projectRoot, BUILD_FOLDER_NAME, "ssg");
18283
18380
  ensureDir(ssgOutDir);
18284
18381
  for (const route of routes) {
18285
18382
  if (route.dynamic !== "force-static") continue;
@@ -18334,36 +18431,36 @@ async function buildStaticPages(projectRoot, routes, config) {
18334
18431
  }
18335
18432
 
18336
18433
  // modules/build/bundler/server.ts
18337
- var import_path33 = __toESM(require("path"));
18338
- var import_fs23 = __toESM(require("fs"));
18434
+ var import_path34 = __toESM(require("path"));
18435
+ var import_fs24 = __toESM(require("fs"));
18339
18436
  var import_esbuild = __toESM(require("esbuild"));
18340
18437
  init_globals();
18341
18438
  var SERVER_FILES = [INIT_FILE_NAME, CONFIG_FILE_NAME];
18342
18439
  function createPathAliasPlugin(projectRoot, outDir) {
18343
18440
  const aliases = loadAliasesFromTsconfig(projectRoot);
18344
- const tsconfigPath = import_path33.default.join(projectRoot, "tsconfig.json");
18441
+ const tsconfigPath = import_path34.default.join(projectRoot, "tsconfig.json");
18345
18442
  let baseUrl = ".";
18346
- if (import_fs23.default.existsSync(tsconfigPath)) {
18443
+ if (import_fs24.default.existsSync(tsconfigPath)) {
18347
18444
  try {
18348
- const tsconfig = JSON.parse(import_fs23.default.readFileSync(tsconfigPath, "utf-8"));
18445
+ const tsconfig = JSON.parse(import_fs24.default.readFileSync(tsconfigPath, "utf-8"));
18349
18446
  baseUrl = tsconfig.compilerOptions?.baseUrl ?? ".";
18350
18447
  } catch {
18351
18448
  }
18352
18449
  }
18353
18450
  function resolveAliasToRelative(importPath, sourceFile) {
18354
- if (importPath.startsWith(".") || importPath.startsWith("/") || import_path33.default.isAbsolute(importPath) || importPath.includes("node_modules")) {
18451
+ if (importPath.startsWith(".") || importPath.startsWith("/") || import_path34.default.isAbsolute(importPath) || importPath.includes("node_modules")) {
18355
18452
  return null;
18356
18453
  }
18357
18454
  for (const [aliasKey, aliasPath] of Object.entries(aliases)) {
18358
18455
  if (importPath.startsWith(aliasKey + "/") || importPath === aliasKey) {
18359
18456
  const restPath = importPath.startsWith(aliasKey + "/") ? importPath.slice(aliasKey.length + 1) : "";
18360
- const resolvedPath = restPath ? import_path33.default.join(aliasPath, restPath) : aliasPath;
18457
+ const resolvedPath = restPath ? import_path34.default.join(aliasPath, restPath) : aliasPath;
18361
18458
  let actualPath = null;
18362
18459
  const extensions = [".ts", ".tsx", ".js", ".jsx", ".json"];
18363
- if (import_fs23.default.existsSync(resolvedPath) && import_fs23.default.statSync(resolvedPath).isDirectory()) {
18460
+ if (import_fs24.default.existsSync(resolvedPath) && import_fs24.default.statSync(resolvedPath).isDirectory()) {
18364
18461
  for (const ext of extensions) {
18365
- const indexPath = import_path33.default.join(resolvedPath, `index${ext}`);
18366
- if (import_fs23.default.existsSync(indexPath)) {
18462
+ const indexPath = import_path34.default.join(resolvedPath, `index${ext}`);
18463
+ if (import_fs24.default.existsSync(indexPath)) {
18367
18464
  actualPath = indexPath;
18368
18465
  break;
18369
18466
  }
@@ -18371,20 +18468,20 @@ function createPathAliasPlugin(projectRoot, outDir) {
18371
18468
  } else {
18372
18469
  for (const ext of extensions) {
18373
18470
  const filePath = resolvedPath + ext;
18374
- if (import_fs23.default.existsSync(filePath)) {
18471
+ if (import_fs24.default.existsSync(filePath)) {
18375
18472
  actualPath = filePath;
18376
18473
  break;
18377
18474
  }
18378
18475
  }
18379
- if (!actualPath && import_fs23.default.existsSync(resolvedPath)) {
18476
+ if (!actualPath && import_fs24.default.existsSync(resolvedPath)) {
18380
18477
  actualPath = resolvedPath;
18381
18478
  }
18382
18479
  }
18383
18480
  if (actualPath) {
18384
- const relativePath = import_path33.default.relative(outDir, actualPath);
18481
+ const relativePath = import_path34.default.relative(outDir, actualPath);
18385
18482
  const normalizedPath = relativePath.replace(/\\/g, "/");
18386
18483
  const finalPath = normalizedPath.startsWith(".") ? normalizedPath : `./${normalizedPath}`;
18387
- const ext = import_path33.default.extname(finalPath);
18484
+ const ext = import_path34.default.extname(finalPath);
18388
18485
  const pathWithoutExt = ext === ".json" ? finalPath : finalPath.slice(0, -ext.length);
18389
18486
  return pathWithoutExt;
18390
18487
  }
@@ -18396,13 +18493,13 @@ function createPathAliasPlugin(projectRoot, outDir) {
18396
18493
  name: "path-alias-resolver",
18397
18494
  setup(build) {
18398
18495
  build.onLoad({ filter: /\.(ts|tsx|js|jsx)$/ }, (args) => {
18399
- const fileName = import_path33.default.basename(args.path);
18496
+ const fileName = import_path34.default.basename(args.path);
18400
18497
  const isServerFile = SERVER_FILES.some((f) => fileName === `${f}.ts` || fileName === `${f}.tsx` || fileName === `${f}.js` || fileName === `${f}.jsx`);
18401
- const isInProjectRoot = import_path33.default.dirname(args.path) === projectRoot;
18498
+ const isInProjectRoot = import_path34.default.dirname(args.path) === projectRoot;
18402
18499
  if (!isServerFile || !isInProjectRoot) {
18403
18500
  return null;
18404
18501
  }
18405
- const contents = import_fs23.default.readFileSync(args.path, "utf-8");
18502
+ const contents = import_fs24.default.readFileSync(args.path, "utf-8");
18406
18503
  let transformed = contents;
18407
18504
  const aliasPatterns = Object.keys(aliases).sort((a, b) => b.length - a.length);
18408
18505
  for (const aliasKey of aliasPatterns) {
@@ -18422,7 +18519,7 @@ function createPathAliasPlugin(projectRoot, outDir) {
18422
18519
  }
18423
18520
  return {
18424
18521
  contents: transformed,
18425
- loader: import_path33.default.extname(args.path).slice(1)
18522
+ loader: import_path34.default.extname(args.path).slice(1)
18426
18523
  };
18427
18524
  });
18428
18525
  build.onResolve({ filter: /.*/ }, (args) => {
@@ -18441,9 +18538,9 @@ function createPathAliasPlugin(projectRoot, outDir) {
18441
18538
  function collectAppSources(appDir) {
18442
18539
  const entries = [];
18443
18540
  function walk(dir) {
18444
- const items = import_fs23.default.readdirSync(dir, { withFileTypes: true });
18541
+ const items = import_fs24.default.readdirSync(dir, { withFileTypes: true });
18445
18542
  for (const item of items) {
18446
- const full = import_path33.default.join(dir, item.name);
18543
+ const full = import_path34.default.join(dir, item.name);
18447
18544
  if (item.isDirectory()) {
18448
18545
  walk(full);
18449
18546
  continue;
@@ -18460,7 +18557,7 @@ function collectAppSources(appDir) {
18460
18557
  return entries;
18461
18558
  }
18462
18559
  async function buildServerApp(projectRoot, appDir) {
18463
- const outDir = import_path33.default.join(projectRoot, BUILD_FOLDER_NAME, "server");
18560
+ const outDir = import_path34.default.join(projectRoot, BUILD_FOLDER_NAME, "server");
18464
18561
  const entryPoints = collectAppSources(appDir);
18465
18562
  ensureDir(outDir);
18466
18563
  if (entryPoints.length === 0) {
@@ -18478,14 +18575,14 @@ async function buildServerApp(projectRoot, appDir) {
18478
18575
  bundle: true,
18479
18576
  splitting: false,
18480
18577
  logLevel: "info",
18481
- tsconfig: import_path33.default.join(projectRoot, "tsconfig.json"),
18578
+ tsconfig: import_path34.default.join(projectRoot, "tsconfig.json"),
18482
18579
  packages: "external"
18483
18580
  });
18484
18581
  const pathAliasPlugin = createPathAliasPlugin(projectRoot, outDir);
18485
18582
  for (const fileName of SERVER_FILES) {
18486
- const initTS = import_path33.default.join(projectRoot, `${fileName}.ts`);
18487
- const initJS = import_path33.default.join(outDir, `${fileName}.js`);
18488
- if (import_fs23.default.existsSync(initTS)) {
18583
+ const initTS = import_path34.default.join(projectRoot, `${fileName}.ts`);
18584
+ const initJS = import_path34.default.join(outDir, `${fileName}.js`);
18585
+ if (import_fs24.default.existsSync(initTS)) {
18489
18586
  await import_esbuild.default.build({
18490
18587
  entryPoints: [initTS],
18491
18588
  outfile: initJS,
@@ -18496,7 +18593,7 @@ async function buildServerApp(projectRoot, appDir) {
18496
18593
  sourcemap: true,
18497
18594
  bundle: false,
18498
18595
  logLevel: "info",
18499
- tsconfig: import_path33.default.join(projectRoot, "tsconfig.json"),
18596
+ tsconfig: import_path34.default.join(projectRoot, "tsconfig.json"),
18500
18597
  plugins: [pathAliasPlugin]
18501
18598
  });
18502
18599
  }
@@ -19783,11 +19880,11 @@ var ValidationError = class extends Error {
19783
19880
  format() {
19784
19881
  const formatted = {};
19785
19882
  for (const error of this.errors) {
19786
- const path30 = error.path.join(".");
19787
- if (!formatted[path30]) {
19788
- formatted[path30] = [];
19883
+ const path31 = error.path.join(".");
19884
+ if (!formatted[path31]) {
19885
+ formatted[path31] = [];
19789
19886
  }
19790
- formatted[path30].push(error.message);
19887
+ formatted[path31].push(error.message);
19791
19888
  }
19792
19889
  return formatted;
19793
19890
  }