ctf-resources/htb/hacktheboo2024/web/web_phantom_script/challenge/routes/index.js

29 lines
672 B
JavaScript
Raw Permalink Normal View History

2024-10-23 11:10:43 +02:00
const express = require("express");
const fs = require("fs");
const router = express.Router();
const { visit } = require("../helpers/botHelper");
router.get("/", (req, res) => {
return res.render("home.html");
});
router.post("/search", (req, res) => {
const { query } = req.body;
if (query) {
try {
visit(query);
return res.status(200).json({ message: "Bot triggered successfully." });
} catch (err) {
return res.status(500).json({ message: "Error triggering bot.", error: err.message });
}
} else {
return res.status(400).json({ message: "No search query provided." });
}
});
module.exports = () => {
return router;
};