mirror of
https://github.com/actix/examples
synced 2024-12-04 18:51:55 +01:00
33 lines
925 B
Rust
33 lines
925 B
Rust
use std::io;
|
|
|
|
use actix_cors::Cors;
|
|
use actix_web::{http::header, middleware::Logger, App, HttpServer};
|
|
|
|
mod user;
|
|
|
|
#[actix_web::main]
|
|
async fn main() -> io::Result<()> {
|
|
env_logger::init_from_env(env_logger::Env::default().default_filter_or("info"));
|
|
|
|
log::info!("starting HTTP server at http://localhost:8080");
|
|
|
|
HttpServer::new(move || {
|
|
App::new()
|
|
.wrap(
|
|
Cors::default()
|
|
.allowed_origin("http://localhost:8081")
|
|
.allowed_methods(vec!["GET", "POST"])
|
|
.allowed_headers(vec![header::AUTHORIZATION, header::ACCEPT])
|
|
.allowed_header(header::CONTENT_TYPE)
|
|
.supports_credentials()
|
|
.max_age(3600),
|
|
)
|
|
.wrap(Logger::default())
|
|
.service(user::info)
|
|
})
|
|
.bind(("127.0.0.1", 8080))?
|
|
.workers(2)
|
|
.run()
|
|
.await
|
|
}
|