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

update deps

This commit is contained in:
Nikolay Kim
2019-03-29 13:43:03 -07:00
parent 48b8e7c335
commit e4f71e8fd5
47 changed files with 307 additions and 415 deletions

View File

@ -1,49 +1,29 @@
#[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,
http::header, middleware::cors::Cors, middleware::Logger, web, App, HttpServer,
};
use std::env;
mod user;
use user::info;
fn main() {
env::set_var("RUST_LOG", "actix_web=info");
fn main() -> std::io::Result<()> {
std::env::set_var("RUST_LOG", "actix_web=info");
env_logger::init();
let sys = actix::System::new("Actix-web-CORS");
server::new(move || {
HttpServer::new(move || {
App::new()
.middleware(middleware::Logger::default())
.configure(|app| {
Cors::for_app(app)
.wrap(
Cors::new()
.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()
})
.max_age(3600),
)
.wrap(Logger::default())
.service(web::resource("/user/info").route(web::post().to(user::info)))
})
.bind("127.0.0.1:8000")
.unwrap()
.shutdown_timeout(2)
.start();
let _ = sys.run();
.bind("127.0.0.1:8000")?
.run()
}

View File

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