-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathmiddleware.js
30 lines (29 loc) · 1.14 KB
/
middleware.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
'use strict';
exports.getEventAndContext = async (request, response, next) => {
if (typeof response === 'function') {
// for koa
let next = response;
request['payload'] = {};
if (request.headers['x-apigateway-event']) {
let event = JSON.parse(decodeURIComponent(request.headers['x-apigateway-event']));
request['payload']['event'] = event;
}
if (request.headers['x-apigateway-context']) {
let context = JSON.parse(decodeURIComponent(request.headers['x-apigateway-context']));
request['payload']['context'] = context;
}
await next();
} else {
// for express
request['payload'] = {};
if (request.headers['x-apigateway-event']) {
let event = JSON.parse(decodeURIComponent(request.headers['x-apigateway-event']));
request['payload']['event'] = event;
}
if (request.headers['x-apigateway-context']) {
let context = JSON.parse(decodeURIComponent(request.headers['x-apigateway-context']));
request['payload']['context'] = context;
}
next();
}
};