${result.title}
${result.meta_url.hostname}${result.description}
import express from "express";
import { Readability, isProbablyReaderable } from "@mozilla/readability";
import got from "got";
import path from "path";
import { fileURLToPath } from "url";
import fetch from "node-fetch";
import "dotenv/config";
import { parseHTML } from "linkedom";
const app = express();
const port = 8888;
// @ts-ignore
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
app.get("/", async (req, res) => {
const searchEngine = "https://api.search.brave.com/res/v1/web/search";
let query = req.query.q as string;
if (!query) {
res.sendFile(path.join(__dirname + "/dist/index.html"));
return;
}
const key = process.env.CYCLIC_BRAVE_KEY;
if (!key) {
throw new Error("No brave key found");
}
fetch(`${searchEngine}?q=${query}`, {
headers: {
Accept: "*/*",
"Accept-Encoding": "gzip, deflate, br",
"X-Subscription-Token": key,
},
})
.then((page) => {
page.json().then((response) => {
const results: any[] = [];
const url = process.env.DEV_MODE
? "http://localhost:8888/blazed"
: "https://blaze.cyclic.app/blazed";
// @ts-ignore
response.web.results.forEach((result) => {
results.push(`
${result.description}${result.title}
${result.meta_url.hostname}