1
0
mirror of https://github.com/actix/examples synced 2025-02-10 12:44:14 +01:00

29 lines
860 B
Rust
Raw Normal View History

2019-06-17 12:48:03 +06:00
use actix_cors::Cors;
use actix_web::{http::header, middleware::Logger, web, App, HttpServer};
mod user;
2019-12-16 13:09:54 +06:00
#[actix_rt::main]
async fn main() -> std::io::Result<()> {
2019-03-29 13:43:03 -07:00
std::env::set_var("RUST_LOG", "actix_web=info");
env_logger::init();
2019-03-29 13:43:03 -07:00
HttpServer::new(move || {
2018-05-08 11:08:43 -07:00
App::new()
2019-03-29 13:43:03 -07:00
.wrap(
Cors::new()
2019-03-30 09:43:07 +08:00
.allowed_origin("http://localhost:8080")
2018-05-08 11:08:43 -07:00
.allowed_methods(vec!["GET", "POST"])
.allowed_headers(vec![header::AUTHORIZATION, header::ACCEPT])
.allowed_header(header::CONTENT_TYPE)
2019-12-16 13:09:54 +06:00
.max_age(3600)
.finish(),
2019-03-29 13:43:03 -07:00
)
.wrap(Logger::default())
.service(web::resource("/user/info").route(web::post().to(user::info)))
2019-03-09 18:03:09 -08:00
})
2019-03-29 13:43:03 -07:00
.bind("127.0.0.1:8000")?
2019-12-25 20:48:33 +04:00
.run()
2019-12-16 13:09:54 +06:00
.await
}