First
This commit is contained in:
commit
4b7cb4ad1e
9 changed files with 1756 additions and 0 deletions
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
/target
|
1685
Cargo.lock
generated
Normal file
1685
Cargo.lock
generated
Normal file
File diff suppressed because it is too large
Load diff
10
Cargo.toml
Normal file
10
Cargo.toml
Normal file
|
@ -0,0 +1,10 @@
|
|||
[package]
|
||||
name = "actix-example"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
actix-web = "4"
|
||||
yew = { git = "https://github.com/yewstack/yew/", features = ["ssr"] }
|
14
src/controllers/hello_controller.rs
Normal file
14
src/controllers/hello_controller.rs
Normal file
|
@ -0,0 +1,14 @@
|
|||
|
||||
use actix_web::{get, Responder, web, HttpResponse};
|
||||
use yew::ServerRenderer;
|
||||
|
||||
use crate::front::components::hello::{Hello, HelloProps};
|
||||
|
||||
#[get("/{name}")]
|
||||
async fn index(name: web::Path<String>) -> impl Responder {
|
||||
let name = name.into_inner();
|
||||
let renderer = ServerRenderer::<Hello>::with_props(HelloProps {
|
||||
name
|
||||
});
|
||||
HttpResponse::Ok().body(renderer.render().await)
|
||||
}
|
1
src/controllers/mod.rs
Normal file
1
src/controllers/mod.rs
Normal file
|
@ -0,0 +1 @@
|
|||
pub mod hello_controller;
|
29
src/front/components/hello.rs
Normal file
29
src/front/components/hello.rs
Normal file
|
@ -0,0 +1,29 @@
|
|||
use yew::prelude::*;
|
||||
|
||||
#[derive(Properties, PartialEq)]
|
||||
pub struct HelloProps {
|
||||
pub name: String,
|
||||
}
|
||||
|
||||
#[function_component]
|
||||
pub fn Hello(props: &HelloProps) -> Html {
|
||||
let counter = use_state(|| 0);
|
||||
let onclick = {
|
||||
let counter = counter.clone();
|
||||
Callback::from(move |_| counter.set(*counter + 1))
|
||||
};
|
||||
|
||||
|
||||
html! {
|
||||
<div>
|
||||
<button {onclick}>{ "Increment value" }</button>
|
||||
<p>
|
||||
<b>{ "Current value: " }</b>
|
||||
{ *counter }
|
||||
</p>
|
||||
<p>
|
||||
{ props.name.clone() }
|
||||
</p>
|
||||
</div>
|
||||
}
|
||||
}
|
1
src/front/components/mod.rs
Normal file
1
src/front/components/mod.rs
Normal file
|
@ -0,0 +1 @@
|
|||
pub mod hello;
|
1
src/front/mod.rs
Normal file
1
src/front/mod.rs
Normal file
|
@ -0,0 +1 @@
|
|||
pub mod components;
|
14
src/main.rs
Normal file
14
src/main.rs
Normal file
|
@ -0,0 +1,14 @@
|
|||
pub(self) mod controllers;
|
||||
pub(self) mod front;
|
||||
|
||||
use actix_web::{App, HttpServer, web};
|
||||
|
||||
#[actix_web::main]
|
||||
async fn main() -> std::io::Result<()>{
|
||||
HttpServer::new(|| {
|
||||
App::new().service(web::scope("/hello").service(controllers::hello_controller::index))
|
||||
})
|
||||
.bind(("127.0.0.1", 8000))?
|
||||
.run()
|
||||
.await
|
||||
}
|
Loading…
Reference in a new issue