stashes 0.1.25 → 0.1.26

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 (3) hide show
  1. package/dist/cli.js +43 -7
  2. package/dist/mcp.js +43 -7
  3. package/package.json +1 -1
package/dist/cli.js CHANGED
@@ -1731,6 +1731,8 @@ function createWebSocketHandler(projectPath, userDevPort, appProxyPort) {
1731
1731
 
1732
1732
  // ../server/dist/services/app-proxy.js
1733
1733
  function startAppProxy(userDevPort, proxyPort, injectOverlay) {
1734
+ const upstreamOrigin = `http://localhost:${userDevPort}`;
1735
+ const proxyOrigin = `http://localhost:${proxyPort}`;
1734
1736
  const server = Bun.serve({
1735
1737
  port: proxyPort,
1736
1738
  async fetch(req, server2) {
@@ -1763,18 +1765,23 @@ function startAppProxy(userDevPort, proxyPort, injectOverlay) {
1763
1765
  redirect: "manual"
1764
1766
  });
1765
1767
  const contentType = response.headers.get("content-type") || "";
1768
+ const respHeaders = new Headers(response.headers);
1769
+ if (response.status >= 300 && response.status < 400) {
1770
+ const location = respHeaders.get("location");
1771
+ if (location?.startsWith(upstreamOrigin)) {
1772
+ respHeaders.set("location", proxyOrigin + location.substring(upstreamOrigin.length));
1773
+ }
1774
+ }
1766
1775
  if (contentType.includes("text/html")) {
1767
1776
  const html = await response.text();
1768
- const injectedHtml = injectOverlay(html);
1769
- const respHeaders2 = new Headers(response.headers);
1770
- respHeaders2.delete("content-encoding");
1771
- respHeaders2.delete("content-length");
1777
+ const injectedHtml = injectOverlay(html, userDevPort, proxyPort);
1778
+ respHeaders.delete("content-encoding");
1779
+ respHeaders.delete("content-length");
1772
1780
  return new Response(injectedHtml, {
1773
1781
  status: response.status,
1774
- headers: respHeaders2
1782
+ headers: respHeaders
1775
1783
  });
1776
1784
  }
1777
- const respHeaders = new Headers(response.headers);
1778
1785
  respHeaders.delete("content-encoding");
1779
1786
  return new Response(response.body, {
1780
1787
  status: response.status,
@@ -1909,7 +1916,7 @@ function startServer(projectPath, userDevPort, port = STASHES_PORT) {
1909
1916
  logger.info("server", `Project: ${projectPath}`);
1910
1917
  return server;
1911
1918
  }
1912
- function injectOverlayScript(html) {
1919
+ function injectOverlayScript(html, upstreamPort, proxyPort) {
1913
1920
  const overlayScript = `
1914
1921
  <script data-stashes-overlay>
1915
1922
  (function() {
@@ -1917,6 +1924,35 @@ function injectOverlayScript(html) {
1917
1924
  var pickerEnabled = false;
1918
1925
  var precisionMode = false;
1919
1926
 
1927
+ // Rewrite cross-origin requests to the upstream dev server through the proxy
1928
+ var upstreamOrigin = 'http://localhost:${upstreamPort}';
1929
+ var proxyOrigin = window.location.origin;
1930
+ if (proxyOrigin !== upstreamOrigin) {
1931
+ function rewriteUrl(url) {
1932
+ if (typeof url === 'string' && (url.startsWith(upstreamOrigin + '/') || url === upstreamOrigin)) {
1933
+ return proxyOrigin + url.substring(upstreamOrigin.length);
1934
+ }
1935
+ return url;
1936
+ }
1937
+ var origFetch = window.fetch;
1938
+ window.fetch = function(input, init) {
1939
+ if (typeof input === 'string') {
1940
+ input = rewriteUrl(input);
1941
+ } else if (input instanceof Request) {
1942
+ var rewritten = rewriteUrl(input.url);
1943
+ if (rewritten !== input.url) { input = new Request(rewritten, input); }
1944
+ }
1945
+ return origFetch.call(window, input, init);
1946
+ };
1947
+ var origXhrOpen = XMLHttpRequest.prototype.open;
1948
+ XMLHttpRequest.prototype.open = function() {
1949
+ if (arguments.length >= 2 && typeof arguments[1] === 'string') {
1950
+ arguments[1] = rewriteUrl(arguments[1]);
1951
+ }
1952
+ return origXhrOpen.apply(this, arguments);
1953
+ };
1954
+ }
1955
+
1920
1956
  function createOverlay() {
1921
1957
  var overlay = document.createElement('div');
1922
1958
  overlay.id = 'stashes-highlight';
package/dist/mcp.js CHANGED
@@ -1927,6 +1927,8 @@ function createWebSocketHandler(projectPath, userDevPort, appProxyPort) {
1927
1927
 
1928
1928
  // ../server/dist/services/app-proxy.js
1929
1929
  function startAppProxy(userDevPort, proxyPort, injectOverlay) {
1930
+ const upstreamOrigin = `http://localhost:${userDevPort}`;
1931
+ const proxyOrigin = `http://localhost:${proxyPort}`;
1930
1932
  const server = Bun.serve({
1931
1933
  port: proxyPort,
1932
1934
  async fetch(req, server2) {
@@ -1959,18 +1961,23 @@ function startAppProxy(userDevPort, proxyPort, injectOverlay) {
1959
1961
  redirect: "manual"
1960
1962
  });
1961
1963
  const contentType = response.headers.get("content-type") || "";
1964
+ const respHeaders = new Headers(response.headers);
1965
+ if (response.status >= 300 && response.status < 400) {
1966
+ const location = respHeaders.get("location");
1967
+ if (location?.startsWith(upstreamOrigin)) {
1968
+ respHeaders.set("location", proxyOrigin + location.substring(upstreamOrigin.length));
1969
+ }
1970
+ }
1962
1971
  if (contentType.includes("text/html")) {
1963
1972
  const html = await response.text();
1964
- const injectedHtml = injectOverlay(html);
1965
- const respHeaders2 = new Headers(response.headers);
1966
- respHeaders2.delete("content-encoding");
1967
- respHeaders2.delete("content-length");
1973
+ const injectedHtml = injectOverlay(html, userDevPort, proxyPort);
1974
+ respHeaders.delete("content-encoding");
1975
+ respHeaders.delete("content-length");
1968
1976
  return new Response(injectedHtml, {
1969
1977
  status: response.status,
1970
- headers: respHeaders2
1978
+ headers: respHeaders
1971
1979
  });
1972
1980
  }
1973
- const respHeaders = new Headers(response.headers);
1974
1981
  respHeaders.delete("content-encoding");
1975
1982
  return new Response(response.body, {
1976
1983
  status: response.status,
@@ -2105,7 +2112,7 @@ function startServer(projectPath, userDevPort, port = STASHES_PORT) {
2105
2112
  logger.info("server", `Project: ${projectPath}`);
2106
2113
  return server;
2107
2114
  }
2108
- function injectOverlayScript(html) {
2115
+ function injectOverlayScript(html, upstreamPort, proxyPort) {
2109
2116
  const overlayScript = `
2110
2117
  <script data-stashes-overlay>
2111
2118
  (function() {
@@ -2113,6 +2120,35 @@ function injectOverlayScript(html) {
2113
2120
  var pickerEnabled = false;
2114
2121
  var precisionMode = false;
2115
2122
 
2123
+ // Rewrite cross-origin requests to the upstream dev server through the proxy
2124
+ var upstreamOrigin = 'http://localhost:${upstreamPort}';
2125
+ var proxyOrigin = window.location.origin;
2126
+ if (proxyOrigin !== upstreamOrigin) {
2127
+ function rewriteUrl(url) {
2128
+ if (typeof url === 'string' && (url.startsWith(upstreamOrigin + '/') || url === upstreamOrigin)) {
2129
+ return proxyOrigin + url.substring(upstreamOrigin.length);
2130
+ }
2131
+ return url;
2132
+ }
2133
+ var origFetch = window.fetch;
2134
+ window.fetch = function(input, init) {
2135
+ if (typeof input === 'string') {
2136
+ input = rewriteUrl(input);
2137
+ } else if (input instanceof Request) {
2138
+ var rewritten = rewriteUrl(input.url);
2139
+ if (rewritten !== input.url) { input = new Request(rewritten, input); }
2140
+ }
2141
+ return origFetch.call(window, input, init);
2142
+ };
2143
+ var origXhrOpen = XMLHttpRequest.prototype.open;
2144
+ XMLHttpRequest.prototype.open = function() {
2145
+ if (arguments.length >= 2 && typeof arguments[1] === 'string') {
2146
+ arguments[1] = rewriteUrl(arguments[1]);
2147
+ }
2148
+ return origXhrOpen.apply(this, arguments);
2149
+ };
2150
+ }
2151
+
2116
2152
  function createOverlay() {
2117
2153
  var overlay = document.createElement('div');
2118
2154
  overlay.id = 'stashes-highlight';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "stashes",
3
- "version": "0.1.25",
3
+ "version": "0.1.26",
4
4
  "type": "module",
5
5
  "description": "Generate AI-powered UI design explorations in your project",
6
6
  "keywords": [