Repository navigation
Add binding type that takes value from system environment variable. - #786
Conversation
4cf800e to
512c92e
Compare
512c92e to
5620ae9
Compare
|
To use that binding, it'll be |
|
@pmbanugo To use it, when declaring bindings in your workerd config, you'd declare a binding like: |
| if (value == nullptr) { | ||
| // TODO(cleanup): Maybe make a Global::Null? (Can't use nullptr_t in OneOf.) For now, | ||
| // using JSON gets the job done hackily. | ||
| return makeGlobal(Global::Json { kj::str("null") }); |
There was a problem hiding this comment.
Setting the value to an empty string would at least have the value test falsy.
console.log('' || 'hello') // 'hello'
console.log('null' || 'hello') // 'null'
There was a problem hiding this comment.
oh, unless Global::Json is setting the value explicitly to null and not 'null'?
There was a problem hiding this comment.
Correct, this is a hack to get the value null, not the string "null".
|
Hey, I am trying to run the functions using workerd binary and in those functions I want to use env variables but I am using wrong key value pair or I don't know exactly. Sharing the files, if anyone could help: .Capnp file: JS CODE: What am I doing wrong?? |
This looks like you are just trying to set the value to
The purpose of
|
|
I tried that, but that js code is not able to pick the value, can you look at the js code once, if you have any idea regarding this. The error I get when I run it: Cannot read properties of undefined (reading 'API_URL')" |
|
@SagarM21 Oh, looking again I see your code is in Service Worker syntax. It looks like you are expecting to find the env as However, we recommend using ES Modules syntax for all new code: https://developers.cloudflare.com/workers/reference/migrate-to-module-workers/ |
|
It worked, and also I have changed the code to ES Modules but after changing the code to ES Modules, its not working, if you can take a look. (the error I get: "Unexpected token export") Below is the updated JS code: }, ` |
|
@SagarM21 Environment variables only show up as globals in service workers syntax. In ES modules syntax, they are on the |
|
Thanks for the info, I am trying to run the wasm file through workerd binary as well, I have written the code in rust and created a wasm file through it and appended it in capnp and its working. capnp const config :Workerd.Config = ( sockets = [ ); const v2892476153958761139Worker :Workerd.Worker = ( ], ], JS CODE TO RUN : `import './wasm_exec.js'; // Import wasm_exec.js to setup the Go WebAssembly runtime import wasmModule from './test.wasm'; // Import your WebAssembly module // Create an instance of the Go WebAssembly runtime const instance = await WebAssembly.instantiate(wasmModule, go.importObject); } test.wasm file which is created through the below code: `//go:build js && wasm package main import ( func add(this js.Value, p []js.Value) interface{} { func main() { Error From the error its clear that, its not able to find add function but what is missing in the code, unable to identify it. |
|
Changed the code a bit and now getting different error: `import './wasm_exec.js'; // Import wasm_exec.js to set up the Go WebAssembly runtime const go = new Go(); // Create a new instance of the Go WebAssembly runtime async function initializeWasm() { // Start the Go runtime // Use the exported initializeWasm();`
|
|
@kentonv can you help me with the above wasm problem? |
|
@SagarM21 This is off-topic for this thread. Please open a discussion thread. |
See discussion on #70
Fixes #70