Created
June 14, 2020 06:11
-
-
Save ta32/0d59b3f6cfd46ec05ac6da77ad366ff4 to your computer and use it in GitHub Desktop.
actix wasm example
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
use actix_web::{App, HttpServer, Responder, HttpResponse, web, get, Result}; | |
use actix_web_static_files; | |
use actix_files as fs; | |
use actix_files::NamedFile; | |
async fn index() -> impl Responder { | |
HttpResponse::Ok().body("Hello world!") | |
} | |
async fn index2() -> impl Responder { | |
HttpResponse::Ok().body("Hello world again!") | |
} | |
#[get("/hello")] | |
async fn index3() -> impl Responder { | |
HttpResponse::Ok().body("Hey there!") | |
} | |
async fn serve_index_html() -> Result<NamedFile> { | |
Ok(NamedFile::open("./wasm-game-of-life/www/dist/static/index.html")?) | |
} | |
#[actix_rt::main] | |
async fn main() -> std::io::Result<()> { | |
HttpServer::new(|| { | |
App::new() | |
.route("/test", web::get().to(index)) | |
.route("/again", web::get().to(index2)) | |
.service(index3) | |
.service(fs::Files::new("/wasm-game-of-life", ".")) | |
.default_service(web::get().to(serve_index_html)) | |
}) | |
.bind("127.0.0.1:8088")? | |
.run() | |
.await | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment