Files
firecrawl/apps/api/src/search/fireEngine.ts
T

59 lines
1.3 KiB
TypeScript
Raw Normal View History

2024-04-23 16:45:06 -07:00
import dotenv from "dotenv";
2024-04-24 10:11:01 -07:00
import { SearchResult } from "../../src/lib/entities";
2024-09-19 12:49:33 -04:00
import * as Sentry from "@sentry/node";
2024-11-07 20:57:33 +01:00
import { logger } from "../lib/logger";
2024-04-23 16:45:06 -07:00
dotenv.config();
2024-09-19 12:49:33 -04:00
export async function fireEngineMap(
q: string,
options: {
tbs?: string;
filter?: string;
lang?: string;
country?: string;
location?: string;
2024-08-16 17:57:11 -03:00
numResults: number;
page?: number;
2024-08-16 17:57:11 -03:00
}
2024-09-19 12:49:33 -04:00
): Promise<SearchResult[]> {
try {
let data = JSON.stringify({
query: q,
lang: options.lang,
country: options.country,
location: options.location,
tbs: options.tbs,
numResults: options.numResults,
page: options.page ?? 1,
});
if (!process.env.FIRE_ENGINE_BETA_URL) {
console.warn(
"(v1/map Beta) Results might differ from cloud offering currently."
);
return [];
}
2024-08-16 17:57:11 -03:00
2024-11-14 17:31:23 -05:00
const response = await fetch(`${process.env.FIRE_ENGINE_BETA_URL}/search`, {
2024-09-19 12:49:33 -04:00
method: "POST",
headers: {
"Content-Type": "application/json",
2024-11-14 17:31:30 -05:00
"X-Disable-Cache": "true",
2024-09-19 12:49:33 -04:00
},
2024-11-14 17:31:30 -05:00
body: data,
2024-11-14 17:31:23 -05:00
});
if (response.ok) {
const responseData = await response.json();
return responseData;
2024-09-19 12:49:33 -04:00
} else {
return [];
}
} catch (error) {
2024-11-07 20:57:33 +01:00
logger.error(error);
2024-09-19 12:49:33 -04:00
Sentry.captureException(error);
2024-04-23 16:45:06 -07:00
return [];
}
}