-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.ts
53 lines (43 loc) · 1.16 KB
/
index.ts
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
/**
* Created by karl on 14/07/15.
*/
/// <reference path="typings/tsd.d.ts" />
'use strict';
var e = require('express');
import CBPromiseRequest = require('./lib/cb-promise-request');
import StreamRequest = require('./lib/stream-request');
function RequestWrap(config) {
return function getRequest(stream:boolean = false, requestOpts?: Object): StreamRequest | CBPromiseRequest {
var $this = this;
if(stream) {
return new StreamRequest({
req: $this,
config: config,
requestOpts: requestOpts
});
}
return new CBPromiseRequest({
req: $this,
config: config,
requestOpts: requestOpts
});
}
}
interface Config {
name: any;
config: {
url:string;
internal?:boolean;
headers?: string[];
cookies?: string[];
replyCookies?: string[];
jSend?: boolean;
opts?: Object;
cleanLogData?: Function;
};
express?: any;
}
export function create(opts: Config) {
var express = opts.express || e;
express.request[opts.name] = RequestWrap(opts.config);
}