2024-12-14 21:40:46 -03:00
|
|
|
import { logger } from "../../../lib/logger";
|
|
|
|
|
import * as Sentry from "@sentry/node";
|
|
|
|
|
import { Request, Response } from "express";
|
|
|
|
|
|
|
|
|
|
export async function checkFireEngine(req: Request, res: Response) {
|
|
|
|
|
try {
|
|
|
|
|
if (!process.env.FIRE_ENGINE_BETA_URL) {
|
|
|
|
|
logger.warn("Fire engine beta URL not configured");
|
|
|
|
|
return res.status(500).json({
|
|
|
|
|
success: false,
|
|
|
|
|
error: "Fire engine beta URL not configured",
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const controller = new AbortController();
|
|
|
|
|
const timeout = setTimeout(() => controller.abort(), 30000);
|
|
|
|
|
|
|
|
|
|
try {
|
2024-12-15 02:54:49 -03:00
|
|
|
const response = await fetch(
|
|
|
|
|
`${process.env.FIRE_ENGINE_BETA_URL}/scrape`,
|
|
|
|
|
{
|
|
|
|
|
method: "POST",
|
|
|
|
|
headers: {
|
|
|
|
|
"Content-Type": "application/json",
|
|
|
|
|
"X-Disable-Cache": "true",
|
|
|
|
|
},
|
|
|
|
|
body: JSON.stringify({
|
2025-01-15 01:16:42 -03:00
|
|
|
url: "https://roastmywebsite.ai",
|
2024-12-15 02:54:49 -03:00
|
|
|
}),
|
|
|
|
|
signal: controller.signal,
|
2024-12-14 21:40:46 -03:00
|
|
|
},
|
2024-12-15 02:54:49 -03:00
|
|
|
);
|
2024-12-14 21:40:46 -03:00
|
|
|
|
|
|
|
|
clearTimeout(timeout);
|
|
|
|
|
|
|
|
|
|
if (response.ok) {
|
|
|
|
|
const responseData = await response.json();
|
|
|
|
|
return res.status(200).json({
|
|
|
|
|
data: responseData,
|
|
|
|
|
});
|
|
|
|
|
} else {
|
|
|
|
|
return res.status(response.status).json({
|
|
|
|
|
success: false,
|
|
|
|
|
error: `Fire engine returned status ${response.status}`,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
} catch (error) {
|
2024-12-15 02:54:49 -03:00
|
|
|
if (error.name === "AbortError") {
|
2024-12-14 21:40:46 -03:00
|
|
|
return res.status(504).json({
|
|
|
|
|
success: false,
|
|
|
|
|
error: "Request timed out after 30 seconds",
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
throw error;
|
|
|
|
|
}
|
|
|
|
|
} catch (error) {
|
|
|
|
|
logger.error(error);
|
|
|
|
|
Sentry.captureException(error);
|
|
|
|
|
return res.status(500).json({
|
|
|
|
|
success: false,
|
|
|
|
|
error: "Internal server error",
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|