(
path: Option<PathBuf>,
port: u16,
reload_rx: Option<broadcast::Receiver<ReloadSignal>>,
)
| 166 | } |
| 167 | |
| 168 | async fn run_server( |
| 169 | path: Option<PathBuf>, |
| 170 | port: u16, |
| 171 | reload_rx: Option<broadcast::Receiver<ReloadSignal>>, |
| 172 | ) { |
| 173 | let config = Config::get(); |
| 174 | |
| 175 | let routes = if let Some(file_path) = path { |
| 176 | read_single_route(&file_path).into_iter().collect() |
| 177 | } else { |
| 178 | read_routes() |
| 179 | }; |
| 180 | |
| 181 | if routes.is_empty() { |
| 182 | eprintln!("Warning: No valid routes found!"); |
| 183 | return; |
| 184 | } |
| 185 | |
| 186 | let mut router = Router::new(); |
| 187 | let openapi = openapi::OpenAPIGenerator::generate(&routes); |
| 188 | router = router.route("/openapi.json", get(move || async { Json(openapi) })); |
| 189 | |
| 190 | if config.apidoc.enabled { |
| 191 | match config.apidoc.doc_type { |
| 192 | config::ApiDocType::Swagger => { |
| 193 | // router = router.route( |
| 194 | // &config.apidoc.path, |
| 195 | // get(move || async { Html(include_str!("openapi/swagger.html")) }), |
| 196 | // ); |
| 197 | } |
| 198 | config::ApiDocType::Redoc => { |
| 199 | router = router.route( |
| 200 | &config.apidoc.path, |
| 201 | get(|| async { Html(include_str!("openapi/redoc.html")) }), |
| 202 | ); |
| 203 | } |
| 204 | } |
| 205 | } |
| 206 | |
| 207 | let pg_connection = get_pg_connection().await; |
| 208 | let sqlite_connection = get_sqlite_connection().await; |
| 209 | let redis_connection = get_redis_connection().await; |
| 210 | for route in routes { |
| 211 | let mut r = Router::new(); |
| 212 | for endpoint_spec in route.endpoints { |
| 213 | let endpoint = Endpoint { |
| 214 | annotation: endpoint_spec.annotation.or(&route.annotation), |
| 215 | path_params: endpoint_spec.path.into_iter().map(convert_field).collect(), |
| 216 | query_params: endpoint_spec.query.into_iter().map(convert_field).collect(), |
| 217 | body_type: endpoint_spec.body.kind, |
| 218 | body_fields: endpoint_spec |
| 219 | .body |
| 220 | .fields |
| 221 | .into_iter() |
| 222 | .map(convert_field) |
| 223 | .collect(), |
| 224 | script: endpoint_spec.statements, |
| 225 | path_specs: endpoint_spec.path_specs, |
no test coverage detected