-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathutls.js
42 lines (34 loc) · 1.23 KB
/
utls.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
function merge(joined, target) {
var sources = [].slice.call(arguments, 2);
sources.forEach(function (source) {
for (var prop in source) {
target[prop] = source[prop];
}
});
output = [];
for (var key in target) {
if (joined.indexOf(key)==-1){
output.push(key,target[key]);
}else{
output.push(key + target[key]);
}
}
output = output.filter(function(n){return n});
console.log(output);
return output;
}
function unknownMethodHandler(req, res) {
if (req.method.toLowerCase() === 'options') {
console.log('received an options method request');
var allowHeaders = ['Accept', 'Accept-Version', 'Content-Type', 'Api-Version', 'Origin', 'X-Requested-With', 'Options', 'X-Access-Token']; // added Origin & X-Requested-With
res.header('Access-Control-Allow-Credentials', true);
res.header('Access-Control-Allow-Headers', allowHeaders.join(', '));
res.header('Access-Control-Allow-Methods', res.methods.join(', '));
res.header('Access-Control-Allow-Origin', req.headers.origin);
return res.send(204);
}
else
return res.send(new restify.MethodNotAllowedError());
}
exports.merge = merge;
exports.unknownMethodHandler = unknownMethodHandler;