Skip to content

Instantly share code, notes, and snippets.

@pichichi91
Last active November 3, 2020 20:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pichichi91/60d3becbc39b83b9e2c64c4626fc9522 to your computer and use it in GitHub Desktop.
Save pichichi91/60d3becbc39b83b9e2c64c4626fc9522 to your computer and use it in GitHub Desktop.
vercel.json
import { Feed } from "feed";
import axios from 'axios';
const name = "SITE_NAME";
const url = "https://yourURL.com"
const backendURL = "https://yourWordpressURL.com"
const email = "you@yourDomain.com"
const imageUrl = backendURL + "/TO_LOGO"
const description = "SITE_DESCRIPTION"
module.exports = (req, res) => {
const feed = new Feed({
title: name,
description: description,
id: url,
link: url,
language: "en", // optional, used only in RSS 2.0, possible values: http://www.w3.org/TR/REC-html40/struct/dirlang.html#langcodes
image: imageUrl,
favicon: url + "/favicon.ico",
copyright: "All rights reserved 2020, " + name,
generator: "awesome", // optional, default = 'Feed for Node.js'
feedLinks: {
json: url + "/feed",
atom: url + "/feed"
},
author: {
name: name,
email: email,
link: url + "feed"
}
});
axios.get(backendURL + '/wp-json/wp/v2/posts')
.then(function (response) {
// handle success
response.data.forEach(post => {
feed.addItem({
title: post.title.rendered,
id: post.link.replace(backendURL, url),
link: post.link.replace(backendURL, url),
description: post.excerpt.rendered,
content: post.content.rendered,
author: [
],
contributor: [
],
date: new Date(Date.parse(post.date_gmt))
});
});
res.setHeader("Content-Type", "application/xml")
res.status(200).send(feed.atom1())
})
}
{
"version": 2,
"builds": [
{
"src": "api/*.js",
"use": "@now/node"
},
{
"src": "package.json",
"use": "@frontity/now"
}
],
"routes": [
{
"src": "/feed",
"headers": { "cache-control": "no-cache" },
"dest": "/api/feed.js"
},
...
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment