1
0
mirror of https://github.com/actix/examples synced 2025-02-13 05:52:20 +01:00

33 lines
925 B
Rust
Raw Normal View History

2023-07-17 22:26:11 +01:00
use std::io;
2019-06-17 12:48:03 +06:00
use actix_cors::Cors;
2020-10-19 23:36:53 +01:00
use actix_web::{http::header, middleware::Logger, App, HttpServer};
mod user;
2020-09-12 16:49:45 +01:00
#[actix_web::main]
2023-07-17 22:26:11 +01:00
async fn main() -> io::Result<()> {
2022-03-15 17:32:27 +00:00
env_logger::init_from_env(env_logger::Env::default().default_filter_or("info"));
2023-07-17 22:26:11 +01:00
log::info!("starting HTTP server at http://localhost:8080");
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(
2020-10-19 23:36:53 +01:00
Cors::default()
2023-07-17 22:26:11 +01:00
.allowed_origin("http://localhost:8081")
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)
2020-10-19 23:36:53 +01:00
.supports_credentials()
.max_age(3600),
2019-03-29 13:43:03 -07:00
)
.wrap(Logger::default())
2020-10-19 23:36:53 +01:00
.service(user::info)
2019-03-09 18:03:09 -08:00
})
2022-03-15 17:32:27 +00:00
.bind(("127.0.0.1", 8080))?
2023-07-18 01:01:26 +01:00
.workers(2)
2019-12-25 20:48:33 +04:00
.run()
2019-12-16 13:09:54 +06:00
.await
}