diff --git a/assets/serve_a_folder/bun_test.ts b/assets/serve_a_folder/bun_test.ts new file mode 100644 index 0000000..b55ccf9 --- /dev/null +++ b/assets/serve_a_folder/bun_test.ts @@ -0,0 +1,26 @@ +// This file gets called like follow: +// +// 1. UI `Index.html` request: +// `http://localhost:xxx/bun_test.ts?foo=123&bar=456` +// +// 2. WebUI runs command: +// `bun run "bun_test.ts" "foo=123&bar=456"` +// +// 3. Bun parses args and prints the response + +// Get Query (HTTP GET) +const args = process.argv.slice(2); +const query = args[0]; + +// Variables +let foo: string = ''; +let bar: string = ''; + +// Read Query +const params = new URLSearchParams(query); +for (const [key, value] of params.entries()) { + if (key === 'foo') foo = value; // 123 + else if (key === 'bar') bar = value; // 456 +} + +console.log('Response from Bun: ' + (parseInt(foo) + parseInt(bar))); // 579 diff --git a/assets/serve_a_folder/deno_test.ts b/assets/serve_a_folder/deno_test.ts index 9e7536b..7ab370d 100644 --- a/assets/serve_a_folder/deno_test.ts +++ b/assets/serve_a_folder/deno_test.ts @@ -1,7 +1,12 @@ // This file gets called like follow: -// `Index.html` -> -// `http://localhost:xxx/deno_test.ts?foo=123&bar=456` -> -// `deno run --allow-all --unstable "deno_test.ts" "foo=123&bar=456"` +// +// 1. UI `Index.html` request: +// `http://localhost:xxx/deno_test.ts?foo=123&bar=456` +// +// 2. WebUI runs command: +// `deno run --allow-all --unstable "deno_test.ts" "foo=123&bar=456"` +// +// 3. Deno parse args and print the response // Import parse() import { parse } from 'https://deno.land/std/flags/mod.ts'; @@ -21,4 +26,4 @@ for (const [key, value] of params.entries()) { else if (key == 'bar') bar = value; // 456 } -console.error('foo + bar = ' + (parseInt(foo) + parseInt(bar))); // 579 +console.log('Response from Deno: ' + (parseInt(foo) + parseInt(bar))); // 579 diff --git a/assets/serve_a_folder/index.html b/assets/serve_a_folder/index.html index 54d406b..c77e094 100644 --- a/assets/serve_a_folder/index.html +++ b/assets/serve_a_folder/index.html @@ -66,7 +66,13 @@