-
-
Save pichichi91/60d3becbc39b83b9e2c64c4626fc9522 to your computer and use it in GitHub Desktop.
vercel.json
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
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()) | |
}) | |
} |
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
{ | |
"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