Created
November 23, 2022 01:10
-
-
Save quinn/67ac75a90a56b9acc4e1d28a471860c8 to your computer and use it in GitHub Desktop.
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
mod templates; | |
use actix_web::{web, App, HttpRequest, HttpServer, Responder}; | |
use perseus::{Html, PerseusApp}; | |
#[cfg(not(target_arch = "wasm32"))] | |
pub async fn dflt_server< | |
M: perseus::stores::MutableStore + 'static, | |
T: perseus::i18n::TranslationsManager + 'static, | |
>( | |
props: perseus::server::ServerProps<M, T>, | |
(host, port): (String, u16), | |
) { | |
use perseus_actix_web::configurer; | |
async fn greet(req: HttpRequest) -> impl Responder { | |
let name = req.match_info().get("name").unwrap_or("World"); | |
format!("Hello {}!", &name) | |
} | |
let cfg = App::new() | |
.route("/", web::get().to(greet)) | |
.route("/{name}", web::get().to(greet)) | |
.configure(configurer(props).await); | |
HttpServer::new(|| App::new()) | |
.bind((host, port)) | |
.expect("failed to start server") | |
.run() | |
.await | |
.expect("end"); | |
} | |
#[perseus::main(dflt_server)] | |
pub fn main<G: Html>() -> PerseusApp<G> { | |
PerseusApp::new().template(crate::templates::index::get_template) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment