1
0
mirror of https://github.com/actix/examples synced 2025-06-29 10:14:58 +02:00

update cors example to 0.5

This commit is contained in:
Rob Ede
2020-10-19 23:36:53 +01:00
parent 15197a271c
commit 5573e5fd34
5 changed files with 61 additions and 26 deletions

View File

@ -1,28 +1,28 @@
use actix_cors::Cors;
use actix_web::{http::header, middleware::Logger, web, App, HttpServer};
use actix_web::{http::header, middleware::Logger, App, HttpServer};
mod user;
#[actix_web::main]
async fn main() -> std::io::Result<()> {
std::env::set_var("RUST_LOG", "actix_web=info");
std::env::set_var("RUST_LOG", "actix=info");
env_logger::init();
HttpServer::new(move || {
App::new()
.wrap(
Cors::new()
Cors::default()
.allowed_origin("http://localhost:8080")
.allowed_methods(vec!["GET", "POST"])
.allowed_headers(vec![header::AUTHORIZATION, header::ACCEPT])
.allowed_header(header::CONTENT_TYPE)
.max_age(3600)
.finish(),
.supports_credentials()
.max_age(3600),
)
.wrap(Logger::default())
.service(web::resource("/user/info").route(web::post().to(user::info)))
.service(user::info)
})
.bind("127.0.0.1:8000")?
.bind(("127.0.0.1", 8000))?
.run()
.await
}

View File

@ -1,4 +1,4 @@
use actix_web::web;
use actix_web::{post, web};
use serde::{Deserialize, Serialize};
#[derive(Deserialize, Serialize, Debug)]
@ -9,6 +9,7 @@ pub struct Info {
confirm_password: String,
}
#[post("/user/info")]
pub async fn info(info: web::Json<Info>) -> web::Json<Info> {
println!("=========={:?}=========", info);
web::Json(Info {