fumadocs-core
Version:
The React.js library for building a documentation website
29 lines (28 loc) • 851 B
JavaScript
//#region src/search/server/endpoint.ts
function createEndpoint(server, options = {}) {
const { search } = server;
const { readOptions = defaultReadOptions } = options;
return {
...server,
async staticGET() {
return Response.json(await server.export());
},
async GET(request) {
const url = new URL(request.url);
const query = url.searchParams.get("query");
if (!query) return Response.json([]);
return Response.json(await search(query, readOptions(url, request)));
}
};
}
function defaultReadOptions(url) {
const params = url.searchParams;
const limit = params.has("limit") ? Number(params.get("limit")) : void 0;
return {
tag: params.get("tag")?.split(","),
locale: params.get("locale"),
limit: Number.isInteger(limit) ? limit : void 0
};
}
//#endregion
export { defaultReadOptions as n, createEndpoint as t };