mirror of
https://github.com/mendableai/firecrawl.git
synced 2024-11-16 03:32:22 +08:00
Add keyAuth
This commit is contained in:
parent
b9fb49c8e1
commit
d280bcadf3
24
apps/api/src/controllers/keyAuth.ts
Normal file
24
apps/api/src/controllers/keyAuth.ts
Normal file
|
@ -0,0 +1,24 @@
|
|||
|
||||
import { AuthResponse, RateLimiterMode } from "../types";
|
||||
|
||||
import { Request, Response } from "express";
|
||||
import { authenticateUser } from "./auth";
|
||||
|
||||
|
||||
export const keyAuthController = async (req: Request, res: Response) => {
|
||||
try {
|
||||
// make sure to authenticate user first, Bearer <token>
|
||||
const { success, team_id, error, status } = await authenticateUser(
|
||||
req,
|
||||
res
|
||||
);
|
||||
if (!success) {
|
||||
return res.status(status).json({ error });
|
||||
}
|
||||
// if success, return success: true
|
||||
return res.status(200).json({ success: true });
|
||||
} catch (error) {
|
||||
return res.status(500).json({ error: error.message });
|
||||
}
|
||||
};
|
||||
|
|
@ -6,6 +6,7 @@ import { crawlPreviewController } from "../../src/controllers/crawlPreview";
|
|||
import { crawlJobStatusPreviewController } from "../../src/controllers/status";
|
||||
import { searchController } from "../../src/controllers/search";
|
||||
import { crawlCancelController } from "../../src/controllers/crawl-cancel";
|
||||
import { keyAuthController } from "../../src/controllers/keyAuth";
|
||||
|
||||
export const v0Router = express.Router();
|
||||
|
||||
|
@ -16,6 +17,9 @@ v0Router.get("/v0/crawl/status/:jobId", crawlStatusController);
|
|||
v0Router.delete("/v0/crawl/cancel/:jobId", crawlCancelController);
|
||||
v0Router.get("/v0/checkJobStatus/:jobId", crawlJobStatusPreviewController);
|
||||
|
||||
// Auth route for key based authentication
|
||||
v0Router.get("/v0/keyAuth", keyAuthController);
|
||||
|
||||
// Search routes
|
||||
v0Router.post("/v0/search", searchController);
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user