diff --git a/bldrs-ai-conway-0.1.655.tgz b/bldrs-ai-conway-0.1.655.tgz deleted file mode 100644 index 90ccf5953..000000000 Binary files a/bldrs-ai-conway-0.1.655.tgz and /dev/null differ diff --git a/bldrs-ai-conway-0.1.670.tgz b/bldrs-ai-conway-0.1.670.tgz new file mode 100644 index 000000000..7fb202eab Binary files /dev/null and b/bldrs-ai-conway-0.1.670.tgz differ diff --git a/bldrs-ai-conway-web-ifc-adapter-0.1.2.tgz b/bldrs-ai-conway-web-ifc-adapter-0.1.2.tgz deleted file mode 100644 index fd0c58647..000000000 Binary files a/bldrs-ai-conway-web-ifc-adapter-0.1.2.tgz and /dev/null differ diff --git a/bldrs-ai-conway-web-ifc-adapter-0.1.3.tgz b/bldrs-ai-conway-web-ifc-adapter-0.1.3.tgz new file mode 100644 index 000000000..053a39ca9 Binary files /dev/null and b/bldrs-ai-conway-web-ifc-adapter-0.1.3.tgz differ diff --git a/package.json b/package.json index ad6981f3f..35b1ad8ec 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "bldrs", - "version": "1.0.1128", + "version": "1.0.1133", "main": "src/index.jsx", "license": "AGPL-3.0", "homepage": "https://github.com/bldrs-ai/Share", @@ -10,8 +10,9 @@ "scripts": { "build": "yarn build-conway", "build-conway": "yarn clean && yarn build-share-conway && yarn build-cosmos", + "build-conway-debug":"yarn clean && yarn build-share-conway && yarn build-share-copy-wasm-conway-profile && yarn build-cosmos", "build-webifc": "yarn clean && yarn build-share-webifc && yarn build-cosmos", - "build-cosmos": "shx mkdir -p docs ; shx rm -rf docs/cosmos; cosmos-export --config .cosmos.config.json && shx mv cosmos-export docs/cosmos", + "build-cosmos": "shx mkdir -p docs && shx rm -rf docs/cosmos && cosmos-export --config .cosmos.config.json && shx mv cosmos-export docs/cosmos", "build-share": "yarn update-version && node tools/esbuild/build.js && shx mkdir -p docs/static/js && shx cp src/OPFS/OPFS.worker.js docs/ && shx cp src/net/github/Cache.js docs/", "build-share-conway": "run-script-os", "build-share-conway:win32": "set USE_WEBIFC_SHIM=true&& yarn build-share", @@ -20,6 +21,7 @@ "build-share-webifc:win32": "set USE_WEBIFC_SHIM=false&& yarn build-share && yarn build-share-copy-wasm-webifc", "build-share-webifc:linux:darwin": "USE_WEBIFC_SHIM=false yarn build-share && yarn build-share-copy-wasm-webifc", "build-share-copy-wasm-webifc": "shx cp node_modules/web-ifc/*.wasm docs/static/js", + "build-share-copy-wasm-conway-profile": "shx cp node_modules/@bldrs-ai/conway-web-ifc-adapter/node_modules/@bldrs-ai/conway/compiled/dependencies/conway-geom/Dist/* docs/static/js", "build-share-analyze": "ANALYZE=true node tools/esbuild/build.js", "clean": "shx rm -rf docs", "cy": "cypress run --browser chrome", @@ -36,8 +38,12 @@ "typecheck": "tsc -p tools/tsconfig.json", "lint-tools": "yarn eslint cypress tools", "precommit": "yarn lint && yarn test", - "serve": "SHARE_CONFIG=dev yarn serve-share-conway", - "serve-prod": "SHARE_CONFIG=prod yarn serve-share-conway", + "serve":"run-script-os", + "serve:win32": "set SHARE_CONFIG=dev && yarn serve-share-conway", + "serve:linux:darwin": "SHARE_CONFIG=dev yarn serve-share-conway", + "serve-prod":"run-script-os", + "serve-prod:win32": "set SHARE_CONFIG=prod && yarn serve-share-conway", + "serve-prod:linux:darwin": "SHARE_CONFIG=prod yarn serve-share-conway", "serve-cosmos": "cosmos --config .cosmos.config.json", "serve-share-conway": "run-script-os", "serve-share-conway:win32": "yarn build-share-conway && set USE_WEBIFC_SHIM=true&& node tools/esbuild/serve.js", @@ -57,8 +63,7 @@ "@babel/plugin-syntax-import-assertions": "7.18.6", "@babel/preset-env": "7.18.10", "@babel/preset-react": "7.18.6", - "@bldrs-ai/conway": "./bldrs-ai-conway-0.1.655.tgz", - "@bldrs-ai/conway-web-ifc-adapter": "./bldrs-ai-conway-web-ifc-adapter-0.1.2.tgz", + "@bldrs-ai/conway-web-ifc-adapter": "./bldrs-ai-conway-web-ifc-adapter-0.1.3.tgz", "@bldrs-ai/ifclib": "5.3.3", "@emotion/react": "11.10.0", "@emotion/styled": "11.10.0", diff --git a/tools/esbuild/proxy.js b/tools/esbuild/proxy.js index 6676697a6..a99541da2 100644 --- a/tools/esbuild/proxy.js +++ b/tools/esbuild/proxy.js @@ -1,13 +1,20 @@ import http from 'node:http' +import https from 'node:https' /** * @param {string} proxiedHost The host to which traffic will be sent. E.g. localhost * @param {number} port The port to which traffic will be sent. E.g. 8079 + * @param {boolean} useHttps Whether to use HTTPS for the proxied server * @return {object} Proxy server * @see https://esbuild.github.io/api/#serve-proxy */ -export function createProxyServer(host, port) { +export function createProxyServer(host, port, useHttps = false) { + const requestModule = useHttps ? https : http + return http.createServer((req, res) => { + // Rewrite the URL if it matches the pattern for a .wasm file + req.url = rewriteUrl(req.url) + const options = { hostname: host, port: port, @@ -16,25 +23,40 @@ export function createProxyServer(host, port) { headers: req.headers, } - // Forward each incoming request to esbuild - const proxyReq = http.request(options, (proxyResponse) => { - // If esbuild cannot find the resource to serve, send our react-router bounce. + // Forward each incoming request to the proxied server + const proxyReq = requestModule.request(options, (proxyResponse) => { + // If proxied server cannot find the resource, send a custom not-found page if (proxyResponse.statusCode === HTTP_NOT_FOUND) { serveNotFound(res) return } - // Set the correct Content-Type for .js files - if (req.url.endsWith('.js')) { - res.setHeader('Content-Type', 'application/javascript') + // Set the correct Content-Type for specific file types + const contentType = getContentType(req.url) + if (contentType) { + res.setHeader('Content-Type', contentType) } - // Otherwise, forward the response from esbuild to the client + // Optionally set Cache-Control headers for static assets + if (isCacheable(req.url)) { + res.setHeader('Cache-Control', 'public, max-age=31536000') + } + + // Forward the response from the proxied server to the client res.writeHead(proxyResponse.statusCode, proxyResponse.headers) proxyResponse.pipe(res, {end: true}) }) - // Forward the body of the request to esbuild + // Handle request errors + proxyReq.on('error', (err) => { + // eslint-disable-next-line no-console + console.error(`Proxy request error: ${err.message}`) + // eslint-disable-next-line no-magic-numbers + res.writeHead(500) + res.end('Internal Server Error') + }) + + // Forward the body of the request to the proxied server req.pipe(proxyReq, {end: true}) }) } @@ -43,7 +65,7 @@ const HTTP_FOUND = 200 const HTTP_NOT_FOUND = 404 /** Serve a 200 bounce page for missing resources. */ -const serveNotFound = ((res) => { +const serveNotFound = (res) => { res.writeHead(HTTP_FOUND, {'Content-Type': 'text/html'}) res.end(` @@ -51,23 +73,62 @@ const serveNotFound = ((res) => { BLDRS - Redirect - Resource not found. Redirecting... + Resource not found. Redirecting... `) -}) +} + +/** + * Rewrite the URL if it's a .wasm file. + * + * @param {string} url The original request URL + * @return {string} The rewritten URL + */ +function rewriteUrl(url) { + // If the URL is for a .wasm file and starts with '/share/v/p/', rewrite it + if (url.endsWith('.wasm') && url.startsWith('/share/v/p/')) { + return url.replace('/share/v/p/', '/') + } + return url +} + +/** + * Get the Content-Type based on file extension. + * + * @param {string} url The request URL + * @return {string|null} The MIME type or null if not recognized + */ +function getContentType(url) { + if (url.endsWith('.js')) { + return 'application/javascript' + } else if (url.endsWith('.wasm')) { + return 'application/wasm' + } else if (url.endsWith('.json')) { + return 'application/json' + } else if (url.endsWith('.css')) { + return 'text/css' + } else if (url.endsWith('.html')) { + return 'text/html' + } + return null +} + +/** + * Determine if a resource is cacheable. + * + * @param {string} url The request URL + * @return {boolean} True if the resource should be cached + */ +function isCacheable(url) { + return /\.(js|css|wasm|png|jpg|jpeg|gif|svg|ico)$/.test(url) +} diff --git a/yarn.lock b/yarn.lock index a31a1b68e..44c4b3399 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2078,17 +2078,17 @@ resolved "https://registry.npmjs.org/@bcoe/v8-coverage/-/v8-coverage-0.2.3.tgz" integrity sha512-0hYQ8SB4Db5zvZB4axdMHGwEaQjkZzFjQiN9LVYvIFB2nSUHW9tYpxWriPrWDASIxiaXax83REcLxuSdnGPZtw== -"@bldrs-ai/conway-web-ifc-adapter@./bldrs-ai-conway-web-ifc-adapter-0.1.2.tgz": - version "0.1.2" - resolved "./bldrs-ai-conway-web-ifc-adapter-0.1.2.tgz#25e6e8f576a66718cd7d81c8880d89ca624995e3" +"@bldrs-ai/conway-web-ifc-adapter@./bldrs-ai-conway-web-ifc-adapter-0.1.3.tgz": + version "0.1.3" + resolved "./bldrs-ai-conway-web-ifc-adapter-0.1.3.tgz#071650ae2ce7e17f620030179baa7287bffd00b5" dependencies: - "@bldrs-ai/conway" "./bldrs-ai-conway-0.1.655.tgz" + "@bldrs-ai/conway" "./bldrs-ai-conway-0.1.670.tgz" "@types/node" "22.5.5" typescript "5.6.2" -"@bldrs-ai/conway@./bldrs-ai-conway-0.1.655.tgz": - version "0.1.655" - resolved "./bldrs-ai-conway-0.1.655.tgz#069513d7388a774883b22b0a54819c413939d07c" +"@bldrs-ai/conway@./bldrs-ai-conway-0.1.670.tgz": + version "0.1.670" + resolved "./bldrs-ai-conway-0.1.670.tgz#3538df2b625f1a582086582fa3dd51c4b4f84556" dependencies: buffer "^6.0.3" gl-matrix "^3.4.3"