2020-09-12 16:21:54 +01:00
|
|
|
#![allow(dead_code)]
|
|
|
|
|
2019-06-19 18:00:31 -04:00
|
|
|
// <config>
|
|
|
|
use actix_web::{web, App, HttpResponse, HttpServer};
|
|
|
|
|
2020-09-04 15:19:43 +03:00
|
|
|
// this function could be located in a different module
|
2019-06-19 18:00:31 -04:00
|
|
|
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)),
|
2019-06-19 18:00:31 -04:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2020-09-04 15:19:43 +03:00
|
|
|
// this function could be located in a different module
|
2019-06-19 18:00:31 -04:00
|
|
|
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)),
|
2019-06-19 18:00:31 -04:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
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<()> {
|
2019-06-19 18:00:31 -04:00
|
|
|
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("/") }),
|
|
|
|
)
|
2019-06-19 18:00:31 -04:00
|
|
|
})
|
2022-02-26 03:56:24 +00:00
|
|
|
.bind(("127.0.0.1", 8080))?
|
2019-06-19 18:00:31 -04:00
|
|
|
.run()
|
2019-12-29 01:15:22 +09:00
|
|
|
.await
|
2019-06-19 18:00:31 -04:00
|
|
|
}
|
|
|
|
// </config>
|