Skip to content

Instantly share code, notes, and snippets.

const fdk=require('@fnproject/fdk');
const wasm=require('@crush-157/rust-fn');
fdk.handle(function(input){
return wasm.hello_json(input);
})
const fdk=require('@fnproject/fdk');
const wasm=require('@crush-157/rust-fn');
fdk.handle(function(input){
let name = 'World';
if (input.name) {
name = input.name;
}
return {'message': wasm.hello_string(name) }
})
{
"name": "hellofn",
"version": "1.0.0",
"description": "example function",
"main": "func.js",
"author": "",
"license": "Apache-2.0",
"dependencies": {
"@fnproject/fdk": ">=0.0.18",
"@crush-157/rust-fn": ">=0.1.0"
[package]
name = "rust-fn"
version = "0.1.0"
authors = ["Ewan Slater <ewan.slater@gmail.com>"]
edition = "2018"
[lib]
crate-type = ["cdylib", "rlib"]
[features]
mod utils;
use wasm_bindgen::prelude::*;
use serde::*;
// When the `wee_alloc` feature is enabled, use `wee_alloc` as the global
// allocator.
#[cfg(feature = "wee_alloc")]
#[global_allocator]
static ALLOC: wee_alloc::WeeAlloc = wee_alloc::WeeAlloc::INIT;
require "http/server"
require "json"
module FnHelper
def self.socket_path
ENV.["FN_LISTENER"].try(&.[5..]) || "/tmp/iofs/lsnr.sock"
end
def self.handle(&block : JSON::Any -> String)
server = HTTP::Server.new do |context|
require "socket"
require "file_utils"
require "http/server"
require "json"
class FnHelper
getter(url : String) { ENV.fetch "FN_LISTENER", "unix:/tmp/iofs/lsnr.sock" }
getter(socket_path : String) { url[5..] }
getter(private_socket_path : String) { socket_path + ".private" }
getter? linked : Bool = false
require "socket"
require "file_utils"
require "http/server"
require "json"
class FnHelper
getter(url : String) { ENV.fetch "FN_LISTENER", "unix:/tmp/iofs/lsnr.sock" }
getter(socket_path : String) { url[5..] }
getter(private_socket_path : String) { socket_path + ".private" }
getter? linked : Bool = false
require "socket"
require "file_utils"
class FnHelper
getter(url : String) { ENV.fetch "FN_LISTENER", "unix:/tmp/iofs/lsnr.sock" }
getter(socket_path : String) { url[5..] }
getter(private_socket_path : String) { socket_path + ".private" }
getter? linked : Bool = false
getter(private_socket : UNIXServer) do
STDERR.puts "HELP, I AM TRAPPED IN A CRYSTAL MAZE!"