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
|
import * as bodyParser from 'body-parser';
import * as express from 'express';
import { constants } from './constants';
import { errorReporter } from './error_reporter';
import { Handler } from './handler';
import { parameterTransformer } from './parameter_transformer';
// Setup the errorReporter to catch uncaught exceptions and unhandled rejections
errorReporter.setup();
const app = express();
app.use(bodyParser.json()); // for parsing application/json
// tslint:disable-next-line:no-unused-variable
app.use((req, res, next) => {
res.header('Access-Control-Allow-Origin', '*');
res.header('Access-Control-Allow-Headers', 'Origin, X-Requested-With, Content-Type, Accept');
next();
});
const handler = new Handler();
// tslint:disable-next-line:no-unused-variable
app.get('/ping', (req: express.Request, res: express.Response) => {
res.status(constants.SUCCESS_STATUS).send('pong');
});
app.get('/info', handler.getQueueInfo.bind(handler));
app.get(
'/ether/:recipient',
parameterTransformer.transform.bind(parameterTransformer),
handler.dispenseEther.bind(handler),
);
app.get(
'/zrx/:recipient',
parameterTransformer.transform.bind(parameterTransformer),
handler.dispenseZRX.bind(handler),
);
app.get(
'/order/weth/:recipient',
parameterTransformer.transform.bind(parameterTransformer),
handler.dispenseWETHOrderAsync.bind(handler),
);
app.get(
'/order/zrx/:recipient',
parameterTransformer.transform.bind(parameterTransformer),
handler.dispenseZRXOrderAsync.bind(handler),
);
// Log to rollbar any errors unhandled by handlers
app.use(errorReporter.errorHandler());
const DEFAULT_PORT = 3000;
const port = process.env.PORT || DEFAULT_PORT;
app.listen(port);
|