Tristan F.-R.
Tristan F.-R.

Reputation: 4204

actix: cannot start server service 0

I have the following main function (CORS is there since I'm using actix to serve a public API):

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)
}

It's using anyhow, actix_web, and actix_cors.

Whenever I run this, an error immideately occurs. How can I fix this?

Upvotes: 3

Views: 551

Answers (1)

Tristan F.-R.
Tristan F.-R.

Reputation: 4204

The underlying issue is actually with CORS, specifically, the implicit call made to Cors#allowed_origin("*").

This is probably a bug, but as of now, you can replace it with ::default and manually call the security laxing that you need:

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)
}

Upvotes: 3

Related Questions