1
0
mirror of https://github.com/actix/actix-extras.git synced 2025-06-26 18:37:41 +02:00

update examples

This commit is contained in:
Nikolay Kim
2018-03-30 18:54:38 -07:00
parent 9e751de707
commit 8d8f6bedad
19 changed files with 137 additions and 104 deletions

View File

@ -5,12 +5,11 @@ extern crate futures;
extern crate actix;
extern crate actix_web;
extern crate env_logger;
extern crate http;
use std::env;
use http::header;
use actix_web::*;
use actix_web::middleware::cors;
use actix_web::{
http, middleware, server,
Application};
mod user;
use user::info;
@ -22,20 +21,21 @@ fn main() {
let sys = actix::System::new("Actix-web-CORS");
HttpServer::new(
server::new(
|| Application::new()
.middleware(middleware::Logger::default())
.resource("/user/info", |r| {
cors::Cors::build()
.allowed_origin("http://localhost:1234")
.allowed_methods(vec!["GET", "POST"])
middleware::cors::Cors::build()
.allowed_origin("http://localhost:1234")
.allowed_methods(vec!["GET", "POST"])
.allowed_headers(
vec![header::AUTHORIZATION,
header::ACCEPT, header::CONTENT_TYPE])
vec![http::header::AUTHORIZATION,
http::header::ACCEPT,
http::header::CONTENT_TYPE])
.max_age(3600)
.finish().expect("Can not create CORS middleware")
.register(r);
r.method(Method::POST).a(info);
r.method(http::Method::POST).a(info);
}))
.bind("127.0.0.1:8000").unwrap()
.shutdown_timeout(200)

View File

@ -11,9 +11,9 @@ struct Info {
}
pub fn info(req: HttpRequest) -> Box<Future<Item=HttpResponse, Error=Error>> {
req.json()
req.json()
.from_err()
.and_then(|res: Info| {
Ok(httpcodes::HTTPOk.build().json(res)?)
Ok(httpcodes::HttpOk.build().json(res)?)
}).responder()
}