Skip to content

Commit 14aa28c

Browse files
authored
Update index.js
1 parent cf7dbf3 commit 14aa28c

File tree

1 file changed

+14
-19
lines changed

1 file changed

+14
-19
lines changed

api/newsfeed/index.js

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,6 @@ app.use((req, res, next) => {
1212
next();
1313
});
1414

15-
app.get("/", (req, res) => {
16-
res.json({
17-
message: "Generate rss feed from our domain",
18-
});
19-
});
20-
2115
app.get("/rss", async (req, res) => {
2216
try {
2317
const sitename = req.query.name;
@@ -38,19 +32,20 @@ app.get("/rss", async (req, res) => {
3832
res.setHeader("Cache-Control", "s-max-age=86400, stale-while-revalidate");
3933
res.set("Content-Type", "application/json");
4034

41-
if (sitename === "news-api") res.send(response.data);
42-
43-
const xmlData = response.data.toString();
44-
45-
parseXML(xmlData)
46-
.then((parsedData) => {
47-
console.log(parsedData);
48-
res.send({ articles: parsedData });
49-
})
50-
.catch((error) => {
51-
console.error("Error parsing XML:", error);
52-
res.status(500).json({ error: "Error parsing XML" });
53-
});
35+
if (sitename === "news-api") {
36+
res.send(response.data);
37+
} else {
38+
const xmlData = response.data.toString();
39+
40+
parseXML(xmlData)
41+
.then((parsedData) => {
42+
res.send({ articles: parsedData });
43+
})
44+
.catch((error) => {
45+
console.error("Error parsing XML:", error);
46+
res.status(500).json({ error: "Error parsing XML" });
47+
});
48+
}
5449
} catch (error) {
5550
if (error instanceof Error) {
5651
res.status(500).json({ type: "error", message: error.message });

0 commit comments

Comments
 (0)