universal-lambda-zig/src/index.js
Emil Lerch 0c6a9366f5
All checks were successful
AWS-Zig Build / build-zig-0.11.0-amd64-host (push) Successful in 1m32s
cloudflare fixes
2023-10-20 22:28:38 -07:00

32 lines
936 B
JavaScript

import customWasm from "custom.wasm";
export default {
async fetch(request, _env2, ctx) {
const stdout = new TransformStream();
console.log(request);
console.log(_env2);
console.log(ctx);
let env = {};
request.headers.forEach((value, key) => {
env[key] = value;
});
const wasi = new WASI({
args: [
"./custom.wasm",
// In a CLI, the first arg is the name of the exe
"--url=" + request.url,
// this contains the target but is the full url, so we will use a different arg for this
"--method=" + request.method,
'-request="' + JSON.stringify(request) + '"'
],
env,
stdin: request.body,
stdout: stdout.writable
});
const instance = new WebAssembly.Instance(customWasm, {
wasi_snapshot_preview1: wasi.wasiImport
});
ctx.waitUntil(wasi.start(instance));
return new Response(stdout.readable);
}
};