forked from CodeGenieApp/serverless-express
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapi-gateway-v1-event.js
169 lines (162 loc) · 4.81 KB
/
api-gateway-v1-event.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
const clone = require('./clone')
const mergeDeep = require('./merge-deep')
const apiGatewayV1Event = {
resource: '/{proxy+}',
path: '/users',
httpMethod: 'POST',
headers: {
Accept: '*/*',
'Accept-Encoding': 'gzip, deflate, br',
'Accept-Language': 'en-US,en;q=0.9',
'cache-control': 'no-cache',
'CloudFront-Forwarded-Proto': 'https',
'CloudFront-Is-Desktop-Viewer': 'true',
'CloudFront-Is-Mobile-Viewer': 'false',
'CloudFront-Is-SmartTV-Viewer': 'false',
'CloudFront-Is-Tablet-Viewer': 'false',
'CloudFront-Viewer-Country': 'US',
'content-type': '',
Host: 'xxxxxx.execute-api.us-east-1.amazonaws.com',
origin: 'https://xxxxxx.execute-api.us-east-1.amazonaws.com',
pragma: 'no-cache',
Referer: 'https://xxxxxx.execute-api.us-east-1.amazonaws.com/prod/',
'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.131 Safari/537.36',
Via: '2.0 00f0a41f749793b9dd653153037c957e.cloudfront.net (CloudFront)',
'X-Amz-Cf-Id': '2D5N65SYHJdnJfEmAV_hC0Mw3QvkbUXDumJKAL786IGHRdq_MggPtA==',
'X-Amzn-Trace-Id': 'Root=1-5cdf30d0-31a428004abe13807f9445b0',
'X-Forwarded-For': '11.111.111.111, 11.111.111.111',
'X-Forwarded-Port': '443',
'X-Forwarded-Proto': 'https'
},
multiValueHeaders: {
Accept: [
'*/*'
],
'Accept-Encoding': [
'gzip, deflate, br'
],
'Accept-Language': [
'en-US,en;q=0.9'
],
'cache-control': [
'no-cache'
],
'CloudFront-Forwarded-Proto': [
'https'
],
'CloudFront-Is-Desktop-Viewer': [
'true'
],
'CloudFront-Is-Mobile-Viewer': [
'false'
],
'CloudFront-Is-SmartTV-Viewer': [
'false'
],
'CloudFront-Is-Tablet-Viewer': [
'false'
],
'CloudFront-Viewer-Country': [
'US'
],
'content-type': [],
Host: [
'xxxxxx.execute-api.us-east-1.amazonaws.com'
],
origin: [
'https://xxxxxx.execute-api.us-east-1.amazonaws.com'
],
pragma: [
'no-cache'
],
Referer: [
'https://xxxxxx.execute-api.us-east-1.amazonaws.com/prod/'
],
'User-Agent': [
'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.131 Safari/537.36'
],
Via: [
'2.0 00f0a41f749793b9dd653153037c957e.cloudfront.net (CloudFront)'
],
'X-Amz-Cf-Id': [
'2D5N65SYHJdnJfEmAV_hC0Mw3QvkbUXDumJKAL786IGHRdq_MggPtA=='
],
'X-Amzn-Trace-Id': [
'Root=1-5cdf30d0-31a428004abe13807f9445b0'
],
'X-Forwarded-For': [
'11.111.111.111, 11.111.111.111'
],
'X-Forwarded-Port': [
'443'
],
'X-Forwarded-Proto': [
'https'
]
},
queryStringParameters: null,
multiValueQueryStringParameters: null,
pathParameters: {
// Default pathParameters.proxy to path (without the '/' prefix)
// 'proxy': 'users'
},
stageVariables: {},
requestContext: {
resourceId: 'xxxxx',
resourcePath: '/{proxy+}',
httpMethod: 'POST',
extendedRequestId: 'Z2SQlEORIAMFjpA=',
requestTime: '17/May/2019:22:08:16 +0000',
// Default requestContext.path to `${requestContext.stage}${path}`
// 'path': '/prod/users',
accountId: 'xxxxxxxx',
protocol: 'HTTP/1.1',
stage: 'prod',
domainPrefix: 'xxxxxx',
requestTimeEpoch: 1558130896565,
requestId: '4589cf16-78f0-11e9-9c65-816a9b037cec',
identity: {
cognitoIdentityPoolId: null,
accountId: null,
cognitoIdentityId: null,
caller: null,
sourceIp: '11.111.111.111',
principalOrgId: null,
accessKey: null,
cognitoAuthenticationType: null,
cognitoAuthenticationProvider: null,
userArn: null,
userAgent: 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.131 Safari/537.36',
user: null
},
domainName: 'xxxxxx.execute-api.us-east-1.amazonaws.com',
apiId: 'xxxxxx'
},
body: '',
isBase64Encoded: false
}
function makeApiGatewayV1Event (values = {}) {
const baseEvent = clone(apiGatewayV1Event)
const mergedEvent = mergeDeep(baseEvent, values)
if (!mergedEvent.pathParameters.proxy) mergedEvent.pathParameters.proxy = values.path.replace(/^\//, '')
if (!mergedEvent.requestContext.path) mergedEvent.requestContext.path = `${mergedEvent.requestContext.stage}${mergedEvent.path}`
return mergedEvent
}
function makeApiGatewayV1Response (values = {}) {
const baseResponse = {
body: '',
isBase64Encoded: false,
statusCode: 200,
multiValueHeaders: {
'content-type': ['application/json; charset=utf-8'],
'x-powered-by': ['Express']
}
}
const mergedResponse = mergeDeep(baseResponse, values)
delete mergedResponse.cookies
return mergedResponse
}
module.exports = {
makeApiGatewayV1Event,
makeApiGatewayV1Response
}