elit 3.3.9 → 3.4.0

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/server.mjs CHANGED
@@ -3568,15 +3568,17 @@ function createDevServer(options) {
3568
3568
  }
3569
3569
  }
3570
3570
  const url = matchedClient.basePath ? originalUrl.slice(matchedClient.basePath.length) || "/" : originalUrl;
3571
- if (matchedClient.api && url.startsWith("/api")) {
3571
+ if (matchedClient.api) {
3572
+ if (matchedClient.basePath) req.url = url;
3572
3573
  const handled = await matchedClient.api.handle(req, res);
3574
+ if (matchedClient.basePath) req.url = originalUrl;
3573
3575
  if (handled) return;
3574
3576
  }
3575
- if (config.api && url.startsWith("/api")) {
3577
+ if (config.api) {
3576
3578
  const handled = await config.api.handle(req, res);
3577
3579
  if (handled) return;
3578
3580
  }
3579
- if (url.startsWith("/api") && ["POST", "PUT", "PATCH", "DELETE"].includes(req.method || "")) {
3581
+ if ((matchedClient.api || config.api) && ["POST", "PUT", "PATCH", "DELETE"].includes(req.method || "")) {
3580
3582
  if (!res.headersSent) {
3581
3583
  if (config.logging) console.log(`[405] ${req.method} ${url} - Method not allowed`);
3582
3584
  res.writeHead(405, { "Content-Type": "application/json" });
@@ -3998,8 +4000,20 @@ ${elitImportMap}` : elitImportMap;
3998
4000
  }
3999
4001
  });
4000
4002
  });
4001
- watcher.on("add", (path) => config.logging && console.log(`[HMR] File added: ${path}`));
4002
- watcher.on("unlink", (path) => config.logging && console.log(`[HMR] File removed: ${path}`));
4003
+ watcher.on("add", (path) => {
4004
+ if (config.logging) console.log(`[HMR] File added: ${path}`);
4005
+ const message = JSON.stringify({ type: "update", path, timestamp: Date.now() });
4006
+ wsClients.forEach((client) => {
4007
+ if (client.readyState === 1 /* OPEN */) client.send(message, {});
4008
+ });
4009
+ });
4010
+ watcher.on("unlink", (path) => {
4011
+ if (config.logging) console.log(`[HMR] File removed: ${path}`);
4012
+ const message = JSON.stringify({ type: "reload", path, timestamp: Date.now() });
4013
+ wsClients.forEach((client) => {
4014
+ if (client.readyState === 1 /* OPEN */) client.send(message, {});
4015
+ });
4016
+ });
4003
4017
  server.setMaxListeners(20);
4004
4018
  server.listen(config.port, config.host, () => {
4005
4019
  if (config.logging) {