1
0
mirror of https://github.com/actix/examples synced 2024-12-01 01:24:35 +01:00
examples/web-cors/backend/src/main.rs

49 lines
1.2 KiB
Rust
Raw Normal View History

2018-05-08 20:08:43 +02:00
#[macro_use]
extern crate serde_derive;
extern crate actix;
extern crate actix_web;
extern crate env_logger;
2018-05-08 20:08:43 +02:00
extern crate futures;
extern crate serde;
extern crate serde_json;
2018-05-21 06:03:29 +02:00
use actix_web::{
2018-07-16 08:36:53 +02:00
http::{header, Method},
middleware,
middleware::cors::Cors,
server, App,
2018-05-21 06:03:29 +02:00
};
use std::env;
mod user;
use user::info;
fn main() {
env::set_var("RUST_LOG", "actix_web=info");
env_logger::init();
let sys = actix::System::new("Actix-web-CORS");
2018-05-08 20:08:43 +02:00
server::new(move || {
App::new()
.middleware(middleware::Logger::default())
2018-05-08 20:08:43 +02:00
.configure(|app| {
Cors::for_app(app)
.allowed_origin("http://localhost:1234")
.allowed_methods(vec!["GET", "POST"])
.allowed_headers(vec![header::AUTHORIZATION, header::ACCEPT])
.allowed_header(header::CONTENT_TYPE)
.max_age(3600)
.resource("/user/info", |r| {
r.method(Method::POST).with(info);
})
.register()
})
}).bind("127.0.0.1:8000")
.unwrap()
2018-04-13 10:03:58 +02:00
.shutdown_timeout(2)
.start();
let _ = sys.run();
}