-
Notifications
You must be signed in to change notification settings - Fork 2
/
app.post-and-get-common-handler.js
50 lines (37 loc) · 1.27 KB
/
app.post-and-get-common-handler.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
const awsServerlessExpressMiddleware = require('aws-serverless-express/middleware')
const encryptionManager = require('./src/utils/encryption-manager')
const MongoDbManager = require('./src/utils/mongo-db-manager')
const bodyParser = require('body-parser')
const express = require('express')
const cors = require('cors')
const app = express()
app.use(cors())
app.use(bodyParser.json())
app.use(bodyParser.urlencoded({extended: true}))
app.use(awsServerlessExpressMiddleware.eventContext())
app.inputObjectOverride = {}
handleRequest = (args, res) => {
/** TODO - Do some things with args here.
*
* someHelperClass.doStuff(args).then( () => {
* ...
*/
res.send({
"hello": "world"
})
}
app.get('/', (req, res) => {
let args = app.inputObjectOverride
if (req.apiGateway)
args = req.apiGateway.event.queryStringParameters || req.apiGateway.event
console.log('Handling User-Embed GET request on ' + process.env.Environment + ' with args: ', args)
handleRequest(args, res)
})
app.post('/', (req, res) => {
let args = app.inputObjectOverride
if (req.apiGateway)
args = req.body || req.apiGateway
console.log('Handling User-Embed POST request on ' + process.env.Environment + ' with args: ', args)
handleRequest(args, res)
})
module.exports = app