(
subsys: SubsystemHandle,
runtime_state: RuntimeState,
cargo_options: CargoOptions,
watcher_config: WatcherConfig,
tls_options: TlsOptions,
disable_cors: bool,
timeout: Op
| 196 | } |
| 197 | |
| 198 | async fn start_server( |
| 199 | subsys: SubsystemHandle, |
| 200 | runtime_state: RuntimeState, |
| 201 | cargo_options: CargoOptions, |
| 202 | watcher_config: WatcherConfig, |
| 203 | tls_options: TlsOptions, |
| 204 | disable_cors: bool, |
| 205 | timeout: Option<Timeout>, |
| 206 | ) -> Result<()> { |
| 207 | let only_lambda_apis = watcher_config.only_lambda_apis; |
| 208 | let init_default_function = |
| 209 | runtime_state.is_default_function_enabled() && watcher_config.send_function_init(); |
| 210 | |
| 211 | let (runtime_addr, proxy_addr, runtime_url) = runtime_state.addresses(); |
| 212 | |
| 213 | let x_request_id = HeaderName::from_static("lambda-runtime-aws-request-id"); |
| 214 | let req_tx = init_scheduler( |
| 215 | &subsys, |
| 216 | runtime_state.clone(), |
| 217 | cargo_options, |
| 218 | watcher_config, |
| 219 | ); |
| 220 | |
| 221 | let state_ref = Arc::new(runtime_state); |
| 222 | let mut app = Router::new() |
| 223 | .merge(trigger_router::routes().with_state(state_ref.clone())) |
| 224 | .nest( |
| 225 | RUNTIME_EMULATOR_PATH, |
| 226 | runtime::routes().with_state(state_ref.clone()), |
| 227 | ) |
| 228 | .layer(SetRequestIdLayer::new( |
| 229 | x_request_id.clone(), |
| 230 | MakeRequestUuid, |
| 231 | )) |
| 232 | .layer(PropagateRequestIdLayer::new(x_request_id)) |
| 233 | .layer(Extension(req_tx.clone())) |
| 234 | .layer(TraceLayer::new_for_http()) |
| 235 | .layer(CatchPanicLayer::new()); |
| 236 | if !disable_cors { |
| 237 | app = app.layer(CorsLayer::very_permissive()); |
| 238 | } |
| 239 | if let Some(timeout) = timeout { |
| 240 | app = app.layer(TimeoutLayer::new(timeout.duration())); |
| 241 | } |
| 242 | let app = app.with_state(state_ref); |
| 243 | |
| 244 | if only_lambda_apis { |
| 245 | info!(""); |
| 246 | info!( |
| 247 | "the flag --only_lambda_apis is active, the lambda function will not be started by Cargo Lambda" |
| 248 | ); |
| 249 | info!("the lambda function will depend on the following environment variables"); |
| 250 | info!( |
| 251 | "you MUST set these variables in the environment where you're running your function:" |
| 252 | ); |
| 253 | info!("AWS_LAMBDA_FUNCTION_VERSION=1"); |
| 254 | info!("AWS_LAMBDA_FUNCTION_MEMORY_SIZE=4096"); |
| 255 | info!("AWS_LAMBDA_RUNTIME_API={}", runtime_url); |
no test coverage detected