Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Example of Jsonnet #302

Merged
merged 4 commits into from
Jan 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file removed .DS_Store
Binary file not shown.
Binary file removed JS/.DS_Store
Binary file not shown.
Binary file modified JS/wasm/crates/wasmjs-engine/wasmjs-engine.wasm
Binary file not shown.
12 changes: 9 additions & 3 deletions JS/wasm/crates/wasmjs-runtime/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,19 @@ pub async fn run(serve_options: ServeOptions) -> Result<()> {

let app_data: Data<AppData> =
Data::new(<ServeOptions as TryInto<AppData>>::try_into(serve_options).unwrap());
let request = actix_web::test::TestRequest::with_uri("/").app_data(app_data).to_http_request();
let request = actix_web::test::TestRequest::with_uri("/").app_data(app_data.clone()).to_http_request();
let request_jsonnet = actix_web::test::TestRequest::with_uri("/jsonnet").app_data(app_data).to_http_request();
let body: Bytes = Bytes::from("");
let req = HttpRequest::from(request);
let res = handle_worker(req, body).await;
let req_jsonnet = HttpRequest::from(request_jsonnet);

let res = handle_worker(req, body.clone()).await;
let res_jsonnet = handle_worker(req_jsonnet,body).await;
// print body of response
let res_body = res.body();

println!("{:?}", res_body);
let res_body = res_jsonnet.body();
println!("{:?}", res_body);

Ok(())
}
8 changes: 8 additions & 0 deletions JS/wasm/crates/wasmjs-runtime/test.jsonnet
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
local Person(name='Alice') = {
name: name,
welcome: 'Hello ' + name + '!',
};
{
person1: Person(),
person2: Person('Bob'),
}
1 change: 1 addition & 0 deletions JS/wasm/examples/ec-wasmjs-hono/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions JS/wasm/examples/ec-wasmjs-hono/src/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Hono } from "hono";
import { connect } from "@planetscale/database";
import { parseJsonnet } from "arakoo-jsonnet"

const app = new Hono();

Expand All @@ -8,6 +9,11 @@ app.get("/", (c) => {
return c.text(`Your from ${geo.city}, ${geo.country_name}!`);
});

app.get("/jsonnet", async (c) => {
const jsonnet = await parseJsonnet('test.jsonnet')
return c.json(JSON.parse(jsonnet));
});

app.get("/hello/:name", async (c) => {
const name = c.req.param("name");
return c.text(`Async Hello ${name}!`);
Expand Down
Loading