(ctx: Data<AppContext>)
| 24 | } |
| 25 | |
| 26 | pub async fn run_actix_server_with_context(ctx: Data<AppContext>) -> std::io::Result<()> { |
| 27 | let config = &ctx.config.clone(); |
| 28 | |
| 29 | let tls = match &config.server.mode { |
| 30 | ServerMode::Https => Some(load_rustls_config(&config.server.ssl)), |
| 31 | ServerMode::Http => { |
| 32 | log::warn!("server.mode=http is not recommended in production"); |
| 33 | None |
| 34 | } |
| 35 | }; |
| 36 | |
| 37 | log::info!( |
| 38 | "starting {} server at {}://{}:{}", |
| 39 | &config.server.mode.protocol().to_uppercase(), |
| 40 | &config.server.mode.protocol(), |
| 41 | &config.server.host, |
| 42 | &config.server.port, |
| 43 | ); |
| 44 | |
| 45 | let server = HttpServer::new(move || { |
| 46 | App::new() |
| 47 | // enable logger |
| 48 | .wrap(middleware::Logger::default()) |
| 49 | // ensure the CORS middleware is wrapped around the httpauth middleware |
| 50 | // so it is able to add headers to error responses |
| 51 | .wrap(Cors::permissive()) |
| 52 | // register simple handler, handle all methods |
| 53 | .app_data(web::JsonConfig::default().limit(8_388_608)) // 8 MB) |
| 54 | .app_data(ctx.clone()) |
| 55 | .service(api_docs_module()) |
| 56 | .service(auth_module()) |
| 57 | .service( |
| 58 | web::scope("/vectordb") |
| 59 | .wrap(AuthenticationMiddleware( |
| 60 | ctx.ain_env.active_sessions.clone(), |
| 61 | )) |
| 62 | // vectors module must be registered before collections module |
| 63 | // as its scope path is more specific than collections module |
| 64 | .service(search_module()) |
| 65 | .service(indexes_module()) |
| 66 | .service(vectors_module()) |
| 67 | .service(transactions_module()) |
| 68 | .service(streaming_module()) |
| 69 | .service(version_module()) |
| 70 | .service(collections_module()), |
| 71 | ) |
| 72 | }) |
| 73 | .keep_alive(std::time::Duration::from_secs(10)); |
| 74 | |
| 75 | let addr = config.server.listen_address(); |
| 76 | let server = match tls { |
| 77 | Some(tls_config) => server.bind_rustls_0_23(addr, tls_config), |
| 78 | None => server.bind(addr), |
| 79 | }; |
| 80 | server?.run().await |
| 81 | } |
| 82 | |
| 83 | fn load_rustls_config(ssl_config: &Ssl) -> rustls::ServerConfig { |
no test coverage detected