Skip to content

Instantly share code, notes, and snippets.

@ta32
Created June 14, 2020 06:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ta32/0d59b3f6cfd46ec05ac6da77ad366ff4 to your computer and use it in GitHub Desktop.
Save ta32/0d59b3f6cfd46ec05ac6da77ad366ff4 to your computer and use it in GitHub Desktop.
actix wasm example
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