diff --git a/examples/sdk-esm/server.dev.mjs b/esbuild.proxy.mjs similarity index 87% rename from examples/sdk-esm/server.dev.mjs rename to esbuild.proxy.mjs index 0b645525..f10ea073 100644 --- a/examples/sdk-esm/server.dev.mjs +++ b/esbuild.proxy.mjs @@ -7,7 +7,14 @@ import http from 'node:http'; export function createProxyServer(localServer, proxyPort = 3000) { const listenerFn = requestListener(localServer); http.createServer(listenerFn).listen(proxyPort); - console.log('\x1b[1m\x1b[92m', '> Proxy: \x1b[4mhttp://' + localServer.host + ':' + proxyPort + '/\x1b[0m\n'); + console.log( + '\x1b[1m\x1b[92m', + '> Proxy: \x1b[4mhttp://' + + localServer.host + + ':' + + proxyPort + + '/\x1b[0m\n' + ); } function requestListener({ host, port }) { diff --git a/examples/sdk-esm/esbuild.dev.mjs b/esbuild.server.mjs similarity index 89% rename from examples/sdk-esm/esbuild.dev.mjs rename to esbuild.server.mjs index c76d4edf..88494729 100644 --- a/examples/sdk-esm/esbuild.dev.mjs +++ b/esbuild.server.mjs @@ -1,5 +1,5 @@ import esbuild from 'esbuild'; -import { createProxyServer } from './server.dev.mjs'; +import { createProxyServer } from './esbuild.proxy.mjs'; const plugins = []; diff --git a/examples/sdk-cjs/package.json b/examples/sdk-cjs/package.json index 9e463c20..0186a48d 100644 --- a/examples/sdk-cjs/package.json +++ b/examples/sdk-cjs/package.json @@ -5,10 +5,11 @@ "scripts": { "start": "node index.cjs" }, + "keywords": [], "devDependencies": { "node": "^21.6.0" }, "dependencies": { - "@galacticcouncil/sdk": "1.1.5" + "@galacticcouncil/sdk": "^1.1.5" } } diff --git a/examples/sdk-esm/package.json b/examples/sdk-esm/package.json index 086d7afa..314f883a 100644 --- a/examples/sdk-esm/package.json +++ b/examples/sdk-esm/package.json @@ -4,13 +4,13 @@ "type": "module", "main": "out/index.js", "scripts": { - "dev": "node ./esbuild.dev.mjs" + "start": "node ../../esbuild.server.mjs" }, "keywords": [], "devDependencies": { "esbuild": "^0.17.11" }, "dependencies": { - "@galacticcouncil/sdk": "^1.1.4" + "@galacticcouncil/sdk": "^1.1.5" } } diff --git a/examples/xcm-transfer/esbuild.dev.mjs b/examples/xcm-transfer/esbuild.dev.mjs deleted file mode 100644 index c76d4edf..00000000 --- a/examples/xcm-transfer/esbuild.dev.mjs +++ /dev/null @@ -1,23 +0,0 @@ -import esbuild from 'esbuild'; -import { createProxyServer } from './server.dev.mjs'; - -const plugins = []; - -const options = { - entryPoints: ['src/index.ts'], - bundle: true, - format: 'esm', - platform: 'browser', - target: 'esnext', - preserveSymlinks: true, - treeShaking: true, - sourcemap: true, - outdir: 'out/', - logLevel: 'info', -}; - -const ctx = await esbuild.context({ ...options, plugins }); -await ctx.rebuild(); -await ctx.watch(); -const localServer = await ctx.serve({ servedir: './', host: '127.0.0.1' }); -createProxyServer(localServer); diff --git a/examples/xcm-transfer/package.json b/examples/xcm-transfer/package.json index 04b50d3f..f76cb8a7 100644 --- a/examples/xcm-transfer/package.json +++ b/examples/xcm-transfer/package.json @@ -4,7 +4,7 @@ "type": "module", "main": "out/index.js", "scripts": { - "dev": "node ./esbuild.dev.mjs" + "start": "node ../../esbuild.server.mjs" }, "keywords": [], "devDependencies": { diff --git a/examples/xcm-transfer/server.dev.mjs b/examples/xcm-transfer/server.dev.mjs deleted file mode 100644 index 0b645525..00000000 --- a/examples/xcm-transfer/server.dev.mjs +++ /dev/null @@ -1,38 +0,0 @@ -import http from 'node:http'; - -/** - * Create proxy server that will forward requests to esbuild local server. - * @see https://esbuild.github.io/api/#serve-proxy - */ -export function createProxyServer(localServer, proxyPort = 3000) { - const listenerFn = requestListener(localServer); - http.createServer(listenerFn).listen(proxyPort); - console.log('\x1b[1m\x1b[92m', '> Proxy: \x1b[4mhttp://' + localServer.host + ':' + proxyPort + '/\x1b[0m\n'); -} - -function requestListener({ host, port }) { - return function (req, res) { - const forwardRequest = (path) => { - const options = { - hostname: host, - port: port, - path, - method: req.method, - headers: req.headers, - }; - - const proxyReq = http.request(options, (proxyRes) => { - // If esbuild local server return 404, use SPA router config for fallback - if (proxyRes.statusCode === 404) { - return forwardRequest('/'); - } - - res.writeHead(proxyRes.statusCode, proxyRes.headers); - proxyRes.pipe(res, { end: true }); - }); - - req.pipe(proxyReq, { end: true }); - }; - forwardRequest(req.url); - }; -}