mirror of
https://github.com/actix/actix-website
synced 2024-11-28 02:22:57 +01:00
35 lines
984 B
Rust
35 lines
984 B
Rust
// <config>
|
|
use actix_web::{web, App, HttpResponse, HttpServer};
|
|
|
|
// this function could be located in different module
|
|
fn scoped_config(cfg: &mut web::ServiceConfig) {
|
|
cfg.service(
|
|
web::resource("/test")
|
|
.route(web::get().to(|| HttpResponse::Ok().body("test")))
|
|
.route(web::head().to(|| HttpResponse::MethodNotAllowed())),
|
|
);
|
|
}
|
|
|
|
// this function could be located in different module
|
|
fn config(cfg: &mut web::ServiceConfig) {
|
|
cfg.service(
|
|
web::resource("/app")
|
|
.route(web::get().to(|| HttpResponse::Ok().body("app")))
|
|
.route(web::head().to(|| HttpResponse::MethodNotAllowed())),
|
|
);
|
|
}
|
|
|
|
pub fn main() {
|
|
HttpServer::new(|| {
|
|
App::new()
|
|
.configure(config)
|
|
.service(web::scope("/api").configure(scoped_config))
|
|
.route("/", web::get().to(|| HttpResponse::Ok().body("/")))
|
|
})
|
|
.bind("127.0.0.1:8088")
|
|
.unwrap()
|
|
.run()
|
|
.unwrap();
|
|
}
|
|
// </config>
|