MCPcopy Index your code
hub / github.com/omkarcloud/botasaurus / buildApp

Function buildApp

js/botasaurus-server-js/src/api-config.ts:470–670  ·  view source on GitHub ↗
(
    scrapers: any[],
    apiBasePath: string,
    routeAliases: any,
    enable_cache: boolean
)

Source from the content-addressed store, hash-verified

468}
469
470export function buildApp(
471 scrapers: any[],
472 apiBasePath: string,
473 routeAliases: any,
474 enable_cache: boolean
475): FastifyInstance {
476 const app = fastify({
477 logger: !isMaster,
478 bodyLimit: 250 * 1024 * 1024 // 250MB (2.5× headroom for 100MB chunks)
479 });
480
481 // Add CORS handling
482 app.addHook("onRequest", (request, reply, done) => {
483 if (request.method === "OPTIONS") {
484 addCorsHeaders(reply);
485 return reply.send();
486 }
487 return done();
488 });
489 app.addHook("onSend", async (_, reply, payload) => {
490 addCorsHeaders(reply);
491 return payload;
492 });
493 // Add error handler for JsonHTTPResponseWithMessage
494 app.setErrorHandler((error:any, _, reply) => {
495 if (error instanceof JsonHTTPResponseWithMessage) {
496 reply.code(error.status).headers(error.headers).send(error.body);
497 } else {
498 console.error(error);
499 // Default error handling
500 reply.status(500).send({
501 message: error.message || "Internal Server Error",
502 });
503 }
504 });
505
506 // Register health endpoint (always available)
507 registerHealthEndpoint(app);
508
509 // Register K8s master routes if this is the master node
510 if (ApiConfig.isMasterNode()) {
511 registerMasterRoutes(app);
512 }
513
514 // Routes
515 app.get(apiBasePath || "/", (_, reply) => {
516 const html = `<!DOCTYPE html><html lang="en"><head><meta charset="utf-8"><link rel="icon" href="https://botasaurus-api.omkar.cloud/favicon.ico"><meta name="viewport" content="width=device-width,initial-scale=1"><meta name="theme-color" content="#000000"><meta name="description" content="API documentation for using web scrapers"><link rel="apple-touch-icon" href="https://botasaurus-api.omkar.cloud/logo192.png"><title>Api Docs</title><script>window.enable_cache=${enable_cache};window.scrapers=${JSON.stringify(
517 scrapers
518 )};window.apiBasePath="${
519 apiBasePath || ""
520 }";window.routeAliases=${JSON.stringify(
521 routeAliases
522 )};</script><script defer="defer" src="https://botasaurus-api.omkar.cloud/static/js/main.e8772f3d.js"></script><link href="https://botasaurus-api.omkar.cloud/static/css/main.69260e80.css" rel="stylesheet"></head><body><noscript>You need to enable JavaScript to run this app.</noscript><div id="root"></div></body></html>`;
523
524 return reply.type("text/html").send(html);
525 });
526
527 app.post(`${apiBasePath}/tasks/create-task-async`, async (request, _) => {

Callers 1

startServerFunction · 0.85

Calls 15

createAsyncTaskFunction · 0.90
createSyncTaskFunction · 0.90
getTasksFunction · 0.90
getTaskFunction · 0.90
getTaskResultsFunction · 0.90
downloadTaskResultsFunction · 0.90
abortSingleTaskFunction · 0.90
deleteSingleTaskFunction · 0.90
bulkAbortTasksFunction · 0.90
bulkDeleteTasksFunction · 0.90
bulkRetryTasksFunction · 0.90
isAnyTaskUpdatedFunction · 0.90

Tested by

no test coverage detected