mirror of
https://git.mirrors.martin98.com/https://github.com/mendableai/firecrawl
synced 2025-08-12 13:48:59 +08:00
Update check-fire-engine.ts
This commit is contained in:
parent
4e8e58729a
commit
24ddcd4a6d
@ -15,6 +15,10 @@ export async function checkFireEngine(req: Request, res: Response) {
|
|||||||
const controller = new AbortController();
|
const controller = new AbortController();
|
||||||
const timeout = setTimeout(() => controller.abort(), 30000);
|
const timeout = setTimeout(() => controller.abort(), 30000);
|
||||||
|
|
||||||
|
const urls = ["https://roastmywebsite.ai", "https://example.com"];
|
||||||
|
let lastError : string | null = null;
|
||||||
|
|
||||||
|
for (const url of urls) {
|
||||||
try {
|
try {
|
||||||
const response = await fetch(
|
const response = await fetch(
|
||||||
`${process.env.FIRE_ENGINE_BETA_URL}/scrape`,
|
`${process.env.FIRE_ENGINE_BETA_URL}/scrape`,
|
||||||
@ -25,7 +29,7 @@ export async function checkFireEngine(req: Request, res: Response) {
|
|||||||
"X-Disable-Cache": "true",
|
"X-Disable-Cache": "true",
|
||||||
},
|
},
|
||||||
body: JSON.stringify({
|
body: JSON.stringify({
|
||||||
url: "https://roastmywebsite.ai",
|
url,
|
||||||
}),
|
}),
|
||||||
signal: controller.signal,
|
signal: controller.signal,
|
||||||
},
|
},
|
||||||
@ -38,12 +42,8 @@ export async function checkFireEngine(req: Request, res: Response) {
|
|||||||
return res.status(200).json({
|
return res.status(200).json({
|
||||||
data: responseData,
|
data: responseData,
|
||||||
});
|
});
|
||||||
} else {
|
|
||||||
return res.status(response.status).json({
|
|
||||||
success: false,
|
|
||||||
error: `Fire engine returned status ${response.status}`,
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
lastError = `Fire engine returned status ${response.status}`;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
if (error.name === "AbortError") {
|
if (error.name === "AbortError") {
|
||||||
return res.status(504).json({
|
return res.status(504).json({
|
||||||
@ -51,8 +51,18 @@ export async function checkFireEngine(req: Request, res: Response) {
|
|||||||
error: "Request timed out after 30 seconds",
|
error: "Request timed out after 30 seconds",
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
throw error;
|
lastError = error;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// If we get here, all retries failed
|
||||||
|
logger.error(lastError);
|
||||||
|
Sentry.captureException(lastError);
|
||||||
|
return res.status(500).json({
|
||||||
|
success: false,
|
||||||
|
error: "Internal server error - all retry attempts failed",
|
||||||
|
});
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logger.error(error);
|
logger.error(error);
|
||||||
Sentry.captureException(error);
|
Sentry.captureException(error);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user