1
0
mirror of https://github.com/actix/examples synced 2025-06-28 18:00:37 +02:00

upgrade actix-web to 0.6

This commit is contained in:
Nikolay Kim
2018-05-08 11:08:43 -07:00
parent 27de52b5d5
commit bbeb262a5c
55 changed files with 689 additions and 518 deletions

View File

@ -1,36 +1,45 @@
#[macro_use] extern crate serde_derive;
extern crate serde;
extern crate serde_json;
extern crate futures;
#[macro_use]
extern crate serde_derive;
extern crate actix;
extern crate actix_web;
extern crate env_logger;
extern crate futures;
extern crate serde;
extern crate serde_json;
use actix_web::{http::{header, Method},
middleware,
middleware::cors::Cors,
server,
App};
use std::env;
use actix_web::{server, App, http::{header, Method}, middleware, middleware::cors::Cors};
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");
server::new(
move || App::new()
server::new(move || {
App::new()
.middleware(middleware::Logger::default())
.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()
.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()
.shutdown_timeout(2)
.start();

View File

@ -1,6 +1,6 @@
use actix_web::{Result, Json};
use actix_web::{Json, Result};
#[derive(Deserialize,Serialize, Debug)]
#[derive(Deserialize, Serialize, Debug)]
pub struct Info {
username: String,
email: String,
@ -10,11 +10,10 @@ pub struct Info {
pub fn info(info: Json<Info>) -> Result<Json<Info>> {
println!("=========={:?}=========", info);
Ok(Json(Info{
username: info.username.clone(),
email: info.email.clone(),
password: info.password.clone(),
confirm_password: info.confirm_password.clone(),
}))
Ok(Json(Info {
username: info.username.clone(),
email: info.email.clone(),
password: info.password.clone(),
confirm_password: info.confirm_password.clone(),
}))
}