generated from fastn-stack/fastn-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
fa14b01
commit a94c0c6
Showing
10 changed files
with
501 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
use flake |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,7 @@ | ||
.direnv | ||
.packages | ||
.build | ||
.DS_Store | ||
.idea | ||
ec/target | ||
ec.wasm |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
[package] | ||
name = "ec" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
||
[lib] | ||
crate-type = ["cdylib"] | ||
|
||
[dependencies] | ||
ft-sdk = "0.1.1" | ||
serde = { version = "1", features = ["derive"] } | ||
serde_json = "1" | ||
http = "1.0" | ||
bytes = "1.0" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
extern crate self as ec; | ||
|
||
mod route; | ||
|
||
#[no_mangle] | ||
pub extern "C" fn main_ft() { | ||
let req = ft_sdk::http::current_request(); | ||
let resp = route::route(req); | ||
ft_sdk::http::send_response(resp); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
pub fn route(r: http::Request<bytes::Bytes>) -> http::Response<bytes::Bytes> { | ||
use ft_sdk::Layout; | ||
|
||
match r.uri().path() { | ||
// site | ||
"/wasm-test/" => Dummy::page::<Hello>(r), | ||
t => ft_sdk::not_found!("no route for {t}"), | ||
} | ||
} | ||
|
||
struct Dummy {} | ||
|
||
impl ft_sdk::Layout for Dummy { | ||
type Error = ft_sdk::Error; | ||
|
||
fn from_in(_in_: ft_sdk::In, _ty: ft_sdk::RequestType) -> Result<Self, Self::Error> { | ||
ft_sdk::println!("from_in 1"); | ||
|
||
Ok(Self {}) | ||
} | ||
|
||
fn json(&mut self, page: serde_json::Value) -> Result<serde_json::Value, Self::Error> { | ||
Ok(serde_json::json!({"page": page})) | ||
} | ||
|
||
fn render_error(e: Self::Error) -> http::Response<bytes::Bytes> { | ||
ft_sdk::println!("rendering error: {e:?}"); | ||
ft_sdk::json_response(serde_json::json!({ | ||
"error": e.to_string(), | ||
})) | ||
} | ||
} | ||
|
||
#[derive(serde::Serialize)] | ||
pub struct Hello { | ||
msg: String, | ||
} | ||
|
||
impl ft_sdk::Page<Dummy, ft_sdk::Error> for Hello { | ||
fn page(_i: &mut Dummy) -> Result<Self, ft_sdk::Error> { | ||
ft_sdk::println!("hello wasm"); | ||
Ok(Hello { | ||
msg: "hello from ft_sdk".into(), | ||
}) | ||
} | ||
} |
Oops, something went wrong.