Skip to content

Commit

Permalink
fix compilation of serverless runtime
Browse files Browse the repository at this point in the history
  • Loading branch information
lovasoa committed Jul 2, 2023
1 parent a1b03f6 commit 4e45ce9
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/app_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use serde::de::Error;
use serde::{Deserialize, Deserializer};
use std::net::{SocketAddr, ToSocketAddrs};

#[cfg(not(feature = "lambda-web"))]
const DEFAULT_DATABASE_FILE: &str = "sqlpage.db";

#[derive(Debug, Deserialize)]
Expand Down
16 changes: 13 additions & 3 deletions src/webserver/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use actix_web::{
};

use actix_web::body::MessageBody;
use anyhow::Context;
use chrono::{DateTime, Utc};
use futures_util::stream::Stream;
use futures_util::StreamExt;
Expand Down Expand Up @@ -428,7 +429,9 @@ pub fn create_app(
impl ServiceFactory<
ServiceRequest,
Config = (),
Response = ServiceResponse<impl MessageBody>,
Response = ServiceResponse<
impl MessageBody<Error = impl std::fmt::Display + std::fmt::Debug>,
>,
Error = actix_web::Error,
InitError = (),
>,
Expand Down Expand Up @@ -460,9 +463,16 @@ pub async fn run_server(config: Config, state: AppState) -> anyhow::Result<()> {

#[cfg(feature = "lambda-web")]
if lambda_web::is_running_on_lambda() {
lambda_web::run_actix_on_lambda(factory).await?;
lambda_web::run_actix_on_lambda(factory)
.await
.map_err(|e| anyhow::anyhow!("Unable to start the lambda: {e}"))?;
return Ok(());
}
HttpServer::new(factory).bind(listen_on)?.run().await?;
HttpServer::new(factory)
.bind(listen_on)
.with_context(|| "Unable to listen to the specified port")?
.run()
.await
.with_context(|| "Unable to start the application")?;
Ok(())
}

0 comments on commit 4e45ce9

Please sign in to comment.