Skip to content

Instantly share code, notes, and snippets.

@theiasapidecv
Created December 27, 2019 21:25
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 theiasapidecv/e3c0f6abcbffe10c75690c166937f2ed to your computer and use it in GitHub Desktop.
Save theiasapidecv/e3c0f6abcbffe10c75690c166937f2ed to your computer and use it in GitHub Desktop.
const express = require('express')
const bodyParser = require('body-parser')
const https = require('https')
const app = express()
app.use((req, res, next) => {
if (req.headers['x-amz-sns-message-type']) {
req.headers['content-type'] = 'application/json; charset=UTF-8';
}
next();
});
app.use(bodyParser.json());
app.post('/', (req, res) => {
let message = req.body
let type = message['Type']
if (type === 'SubscriptionConfirmation') {
https.get(message['SubscribeURL'])
res.status(200).end()
} else if (type === 'Notification') {
let subject = message['Subject']
if ( subject === 'New Study') {
console.log(JSON.parse(message['Message']))
res.status(200).end()
} else if (subject === 'New Interpretation') {
console.log(JSON.parse(message['Message']))
res.status(200).end()
} else {
res.status(400).end()
}
} else {
res.status(400).end()
}
})
app.listen(5000)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment