mirror of
https://git.mirrors.martin98.com/https://github.com/mendableai/firecrawl
synced 2025-08-12 17:09:10 +08:00
Nick: f-eng monitoring test
This commit is contained in:
parent
c325c3aa33
commit
664ba69f08
62
apps/api/src/controllers/v0/admin/check-fire-engine.ts
Normal file
62
apps/api/src/controllers/v0/admin/check-fire-engine.ts
Normal file
@ -0,0 +1,62 @@
|
||||
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 {
|
||||
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({
|
||||
url: "https://example.com",
|
||||
}),
|
||||
signal: controller.signal,
|
||||
});
|
||||
|
||||
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) {
|
||||
if (error.name === 'AbortError') {
|
||||
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",
|
||||
});
|
||||
}
|
||||
}
|
@ -8,6 +8,7 @@ import {
|
||||
} from "../controllers/v0/admin/queue";
|
||||
import { wrap } from "./v1";
|
||||
import { acucCacheClearController } from "../controllers/v0/admin/acuc-cache-clear";
|
||||
import { checkFireEngine } from "../controllers/v0/admin/check-fire-engine";
|
||||
|
||||
export const adminRouter = express.Router();
|
||||
|
||||
@ -37,3 +38,8 @@ adminRouter.post(
|
||||
`/admin/${process.env.BULL_AUTH_KEY}/acuc-cache-clear`,
|
||||
wrap(acucCacheClearController),
|
||||
);
|
||||
|
||||
adminRouter.get(
|
||||
`/admin/${process.env.BULL_AUTH_KEY}/feng-check`,
|
||||
wrap(checkFireEngine),
|
||||
);
|
||||
|
Loading…
x
Reference in New Issue
Block a user