-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathlambda-utils.js
156 lines (123 loc) · 3.42 KB
/
lambda-utils.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
module.exports.buildRequest = function(event, context, cb) {
var req = {};
// http://expressjs.com/en/api.html#req
// Properties
req.app = null; // Not sure this applies in our context...
req.baseUrl = event.baseUrl;
req.body = event.body;
req.cookies = {}; // TODO : Figure out how to get cookies from AWS Gateway
req.fresh = true; // TODO : Does this apply in our context?
req.hostname = event.headers.Host;
//req.ip = event.headers["X-Forwarded-For"].split(", ")[0];
req.ips = event.headers["X-Forwarded-For"];
req.method = event.method;
req.originalUrl = ""; // TODO : Figrure out how to reconstruct this
req.params = event.params;
req.path = event.baseUrl; // TODO : This isn't quite right...
req.protocol = event.headers["X-Forwarded-Proto"];
req.query = event.query;
req.route = null; // TODO : Does this apply to us?
req.secure = req.protocol === 'https';
req.signedCookies = {}; // TODO : ???
req.stale = false; // TODO : Does this apply in our context?
req.subdomains = []; // TODO: Does this apply?
req.xhr = event.headers["X-Requested-With"] === 'XMLHttpRequest';
// Methods
/*
var accept = realAccepts(req);
req.accepts = function accepts(types){
// TODO : Fix me!
return types;
//return accept.type(types);
};
*/
req.acceptsCharsets = function acceptsCharsets(){
// TODO : Fix me!
};
req.acceptsEncodings = function acceptsEncodings(){
// TODO : Fix me!
};
req.acceptsLanguages = function acceptsLanguages(){
// TODO : Fix me!
};
req.get = function get(field){
return event.headers[field];
}
req.is = function is(type){
// TODO: Fix me!
}
return req;
}
module.exports.buildResponse = function(event, context, cb) {
var res = {};
// Properties
res.app = null; // TODO : Does this apply?
res.headersSent = false; // TODO : Is this right?
res.locals = {}; // TODO: Does this apply?
res.headers = [];
// Methods
res.append = function append(field,value){
res.headers.push([field,value]);
}
res.attachment = function attachment(){
// TODO: Can we return attachments through API Gatewway?
}
res.cookie = function cookie(name, value, options){
// TODO: Can we set cookies?
}
res.clearCookie = function clearCookie(name, options){
// TODO: Can we set cookies?
}
res.download = function download(){
// TODO: Can we do this?
}
res.end = function end(){
// TODO: Implement me!
}
res.format = function format(){
// TODO: does this apply?
}
res.get = function get(field){
return headers[field];
}
res.json = function json(payload){
cb(null, payload);
}
res.jsonp = function jsonp(){
// TODO: Do we need to support josnp?
}
res.links = function links(){
// TODO: Implement me!
}
res.location = function location(){
// TODO: Implement me!
}
res.redirect = function redirect(){
// TODO: Implement me!
}
res.render = function render(){
// TODO: Does this apply?
}
res.send = function send(){
// TODO: Does this apply?
}
res.sendFile = function sendFile(){
// TODO: Does this apply?
}
res.sendStatus = function sendStatus(){
// TODO: Implement me!
}
res.set = function set(){
// TODO: Implement me!
}
res.status = function status(){
// TODO: Implement me!
}
res.type = function type(){
// TODO: Implement me!
}
res.vary = function vary(){
// TODO: Implement me!
}
return res;
}