1
0
mirror of https://github.com/actix/actix-website synced 2025-03-11 02:42:43 +01:00

40 lines
1.1 KiB
Rust
Raw Normal View History

2020-09-12 16:21:54 +01:00
#![allow(dead_code)]
// <config>
use actix_web::{web, App, HttpResponse, HttpServer};
// this function could be located in a different module
fn scoped_config(cfg: &mut web::ServiceConfig) {
cfg.service(
web::resource("/test")
2022-02-26 03:56:24 +00:00
.route(web::get().to(|| async { HttpResponse::Ok().body("test") }))
.route(web::head().to(HttpResponse::MethodNotAllowed)),
);
}
// this function could be located in a different module
fn config(cfg: &mut web::ServiceConfig) {
cfg.service(
web::resource("/app")
2022-02-26 03:56:24 +00:00
.route(web::get().to(|| async { HttpResponse::Ok().body("app") }))
.route(web::head().to(HttpResponse::MethodNotAllowed)),
);
}
2020-09-12 16:21:54 +01:00
#[actix_web::main]
2019-12-29 01:15:22 +09:00
async fn main() -> std::io::Result<()> {
HttpServer::new(|| {
App::new()
.configure(config)
.service(web::scope("/api").configure(scoped_config))
2022-02-26 03:56:24 +00:00
.route(
"/",
web::get().to(|| async { HttpResponse::Ok().body("/") }),
)
})
2022-02-26 03:56:24 +00:00
.bind(("127.0.0.1", 8080))?
.run()
2019-12-29 01:15:22 +09:00
.await
}
// </config>