-
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #324 from ashik-75/work
Add Serverless function for RSS feed and fix issue
- Loading branch information
Showing
16 changed files
with
2,090 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
node_modules | ||
.env | ||
|
||
.yarn |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
nodeLinker: "node-modules" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import express from "express"; | ||
import axios from "axios"; | ||
|
||
const app = express(); | ||
|
||
app.use((req, res, next) => { | ||
const environment = process.env.NODE_ENV || "development"; | ||
let origin = | ||
environment === "development" ? "*" : "https://www.binarytree.dev"; | ||
res.header("Access-Control-Allow-Origin", origin); | ||
next(); | ||
}); | ||
|
||
app.get("/", (req, res) => { | ||
res.json({ | ||
message: "Generate rss feed from our domain", | ||
}); | ||
}); | ||
|
||
app.get("/rss", async (req, res) => { | ||
try { | ||
const sitename = req.query.name; | ||
const sites = { | ||
"frontend-focus": "https://cprss.s3.amazonaws.com/frontendfoc.us.xml", | ||
"status-code": "https://cprss.s3.amazonaws.com/react.statuscode.com.xml", | ||
}; | ||
const response = await axios.get(sites[sitename], { | ||
responseType: "arraybuffer", | ||
}); | ||
|
||
if (response.status !== 200) { | ||
throw new Error("Failed to fetch the Medium RSS feed"); | ||
} | ||
|
||
res.set("Content-Type", "application/xml"); | ||
|
||
res.send(response.data); | ||
} catch (error) { | ||
if (error instanceof Error) { | ||
res.status(500).json({ type: "error", message: error.message }); | ||
} else { | ||
res.status(500).json({ message: "Something went wrong" }); | ||
} | ||
} | ||
}); | ||
|
||
const PORT = 5000; | ||
|
||
app.listen(PORT, () => console.log(`Listening on port ${PORT}`)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
{ | ||
"name": "newsfeed", | ||
"version": "1.0.0", | ||
"description": "", | ||
"main": "index.js", | ||
"type": "module", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1", | ||
"dev": "nodemon index.js", | ||
"start": "node index.js", | ||
"vercel-build": "echo helllo" | ||
}, | ||
"keywords": [], | ||
"author": "", | ||
"license": "ISC", | ||
"dependencies": { | ||
"axios": "^1.5.0", | ||
"express": "^4.18.2", | ||
"rss-parser": "^3.13.0" | ||
}, | ||
"devDependencies": { | ||
"nodemon": "^3.0.1" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{ | ||
"version": 2, | ||
"builds": [ | ||
{ | ||
"src": "index.js", | ||
"use": "@vercel/node" | ||
} | ||
], | ||
"routes": [ | ||
{ | ||
"src": "/(.*)", | ||
"dest": "index.js" | ||
} | ||
] | ||
} |
Oops, something went wrong.