【问题标题】:actix: cannot start server service 0actix: 无法启动服务器服务 0
【发布时间】:2022-12-21 02:27:21
【问题描述】:

我有以下主要功能(因为我使用 actix 来提供公共 API,所以有 CORS):

use actix_cors::Cors;
use anyhow::Result;
use actix_web::{App, HttpServer};

#[actix_web::main]
async fn main() -> Result<()> {
    HttpServer::new(|| App::new().wrap(Cors::permissive().send_wildcard()))
        .bind(("localhost", 8080))?
        .run()
        .await
        .map_err(anyhow::Error::from)
}

它使用 anyhowactix_webactix_cors

每当我运行它时,都会立即发生错误。我怎样才能解决这个问题?

【问题讨论】:

    标签: rust actix-web


    【解决方案1】:

    根本问题实际上与 CORS 有关,特别是对 Cors#allowed_origin("*") 的隐式调用。

    这可能是一个错误,但截至目前,您可以将其替换为 ::default 并手动调用您需要的安全性松弛:

    use actix_cors::Cors;
    use anyhow::Result;
    use actix_web::{App, HttpServer};
    
    #[actix_web::main]
    async fn main() -> Result<()> {
        HttpServer::new(|| App::new().wrap(Cors::default().allow_any_origin().send_wildcard()))
            .bind(("localhost", 8080))?
            .run()
            .await
            .map_err(anyhow::Error::from)
    }
    

    【讨论】:

      猜你喜欢
      • 2019-03-28
      • 2019-07-20
      • 1970-01-01
      • 2011-08-05
      • 2017-04-23
      • 2013-12-08
      • 2015-08-15
      • 2021-07-08
      • 2013-06-05
      相关资源
      最近更新 更多