30 lines
858 B
JavaScript
30 lines
858 B
JavaScript
// server.js
|
||
import { serve } from "bun";
|
||
import { fetchRSS } from "./rss.js";
|
||
import { analyzeContent } from "./ai.js";
|
||
import { getWeChatArticleLinks } from "./wechat.js";
|
||
const PORT = 3000;
|
||
|
||
async function handleRequest(request) {
|
||
// 从环境变量中获取 RSS URL,如果没有则使用默认值
|
||
const rssUrl = "https://mp.weixin.qq.com/s/vQgsMuxXffpFZkNFj89wUQ";
|
||
try {
|
||
const rssContent = await fetchRSS(rssUrl);
|
||
const analyzedContent = await analyzeContent(rssContent);
|
||
|
||
return new Response(analyzedContent, {
|
||
headers: { "Content-Type": "text/markdown" },
|
||
});
|
||
} catch (error) {
|
||
console.error("Error processing request:", error);
|
||
return new Response("Error processing request", { status: 500 });
|
||
}
|
||
}
|
||
|
||
serve({
|
||
port: PORT,
|
||
fetch: handleRequest,
|
||
});
|
||
|
||
console.log(`Server running at http://localhost:${PORT}`);
|