forked from diadistis/dpd-proxy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
36 lines (28 loc) · 881 Bytes
/
index.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
var
Resource = require('deployd/lib/resource'),
util = require('util'),
url = require('url'),
curl = require('curlrequest');
function Proxy(name, options) {
Resource.apply(this, arguments);
}
util.inherits(Proxy, Resource);
module.exports = Proxy;
Proxy.prototype.clientGeneration = true;
Proxy.prototype.handle = function (ctx, next) {
if(ctx.req && ctx.req.method !== 'GET') return next();
var completionCallback = function(error, response){
if (error) {
console.error(error);
// Bad request
ctx.res.statusCode = 400;
ctx.res.end();
}else{
ctx.res.write(response);
ctx.res.statusCode = 200;
ctx.res.end();
}
};
var fetchRequest = {url: decodeURIComponent(ctx.query.url)};
curl.request(fetchRequest, completionCallback);
};