-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d3a9514
commit e84e390
Showing
7 changed files
with
39 additions
and
101 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
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
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
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
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
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 |
---|---|---|
@@ -1,21 +1,33 @@ | ||
const RssToEmail = require('rss-to-email'); | ||
|
||
module.exports = (request, response) => { | ||
const config = request.body || {}; | ||
const rssToEmail = RssToEmail(config); | ||
const headers = {}; | ||
headers['Access-Control-Allow-Origin'] = '*'; | ||
headers['Access-Control-Allow-Methods'] = 'POST, GET, PUT, DELETE, OPTIONS'; | ||
headers['Access-Control-Allow-Headers'] = 'X-Requested-With, X-HTTP-Method-Override, Content-Type, Accept'; | ||
|
||
rssToEmail.getEmail(config.format || 'html') | ||
.then(email => { | ||
response.writeHead(200, { | ||
'Content-Type': 'text/html ', | ||
}); | ||
response.end(email); | ||
}) | ||
.catch(e => { | ||
console.error(e); | ||
response.writeHead(500, { | ||
'Content-Type': 'text/html ', | ||
if (request.method === 'OPTIONS') { | ||
response.writeHead(204, headers); | ||
response.end(); | ||
} else { | ||
const config = request.body || {}; | ||
const rssToEmail = RssToEmail(config); | ||
|
||
rssToEmail.getEmail(config.format || 'html') | ||
.then(email => { | ||
response.writeHead(200, { | ||
...headers, | ||
'Content-Type': 'text/html ', | ||
}); | ||
response.end(email); | ||
}) | ||
.catch(e => { | ||
console.error(e); | ||
response.writeHead(500, { | ||
...headers, | ||
'Content-Type': 'text/html ', | ||
}); | ||
response.end('Something went wrong. Please check the server logs for more info.') | ||
}); | ||
response.end('Something went wrong. Please check the server logs for more info.') | ||
}); | ||
} | ||
}; |