Add server subcommand
This commit is contained in:
@@ -48,13 +48,10 @@ pub async fn lookup(
|
||||
Json(body): Json<LookupRequest>,
|
||||
) -> Response {
|
||||
let start = Instant::now();
|
||||
debug!(
|
||||
message = "Serving /lookup",
|
||||
query = body.query,
|
||||
limit = body.limit.unwrap_or(10)
|
||||
);
|
||||
let limit = body.limit.unwrap_or(128).min(1024);
|
||||
debug!(message = "Serving /lookup", query = body.query, limit);
|
||||
|
||||
let results: Vec<LookupResult> = match state.fts_lookup(&body.query, body.limit.unwrap_or(10)) {
|
||||
let results: Vec<LookupResult> = match state.fts_lookup(&body.query, limit) {
|
||||
Ok(x) => x
|
||||
.into_iter()
|
||||
.map(|x| LookupResult {
|
||||
|
||||
@@ -28,20 +28,32 @@ pub(crate) struct Api;
|
||||
impl Datasets {
|
||||
#[inline]
|
||||
pub fn router(self: Arc<Self>, with_docs: bool) -> Router<()> {
|
||||
self.router_prefix(with_docs, None)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn router_prefix(self: Arc<Self>, with_docs: bool, prefix: Option<&str>) -> Router<()> {
|
||||
let mut router = Router::new()
|
||||
.route("/lookup", post(lookup))
|
||||
.route("/item", get(item_get))
|
||||
.route("/field", get(get_field))
|
||||
.with_state(self.clone());
|
||||
|
||||
if let Some(prefix) = prefix {
|
||||
router = Router::new().nest(prefix, router);
|
||||
}
|
||||
|
||||
if with_docs {
|
||||
let docs_path = "/docs";
|
||||
let docs = SwaggerUi::new(docs_path)
|
||||
let docs_path = match prefix {
|
||||
None => "/docs".into(),
|
||||
Some(prefix) => format!("{prefix}/docs"),
|
||||
};
|
||||
|
||||
let docs = SwaggerUi::new(docs_path.clone())
|
||||
.url(format!("{}/openapi.json", docs_path), Api::openapi());
|
||||
|
||||
router = router.merge(docs);
|
||||
}
|
||||
|
||||
router
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user