Created
December 27, 2019 21:25
-
-
Save theiasapidecv/e3c0f6abcbffe10c75690c166937f2ed to your computer and use it in GitHub Desktop.
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
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