MCPcopy Index your code
hub / github.com/aiscriptdev/aiscript / run_server

Function run_server

aiscript-runtime/src/lib.rs:168–302  ·  view source on GitHub ↗
(
    path: Option<PathBuf>,
    port: u16,
    reload_rx: Option<broadcast::Receiver<ReloadSignal>>,
)

Source from the content-addressed store, hash-verified

166}
167
168async 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,

Callers 1

runFunction · 0.85

Calls 10

getFunction · 0.85
read_single_routeFunction · 0.85
read_routesFunction · 0.85
get_pg_connectionFunction · 0.85
get_sqlite_connectionFunction · 0.85
get_redis_connectionFunction · 0.85
lenMethod · 0.80
orMethod · 0.45
as_refMethod · 0.45
cloneMethod · 0.45

Tested by

no test coverage detected