aboutsummaryrefslogtreecommitdiffstats
path: root/packages/kovan-faucets/src/ts/server.ts
diff options
context:
space:
mode:
authorBrandon Millman <brandon.millman@gmail.com>2017-11-21 05:12:15 +0800
committerBrandon Millman <brandon.millman@gmail.com>2017-12-13 07:45:22 +0800
commitbbb768c5cfa8bf713670608f859debae42b42898 (patch)
tree40ae6f11995fa44a1ee58092a8308faac63abec4 /packages/kovan-faucets/src/ts/server.ts
parent5678196706a63d27fc5b00b5224c8213510e76f0 (diff)
downloaddexon-sol-tools-bbb768c5cfa8bf713670608f859debae42b42898.tar
dexon-sol-tools-bbb768c5cfa8bf713670608f859debae42b42898.tar.gz
dexon-sol-tools-bbb768c5cfa8bf713670608f859debae42b42898.tar.bz2
dexon-sol-tools-bbb768c5cfa8bf713670608f859debae42b42898.tar.lz
dexon-sol-tools-bbb768c5cfa8bf713670608f859debae42b42898.tar.xz
dexon-sol-tools-bbb768c5cfa8bf713670608f859debae42b42898.tar.zst
dexon-sol-tools-bbb768c5cfa8bf713670608f859debae42b42898.zip
Add kovan faucet project into the mono repo
Diffstat (limited to 'packages/kovan-faucets/src/ts/server.ts')
-rw-r--r--packages/kovan-faucets/src/ts/server.ts27
1 files changed, 27 insertions, 0 deletions
diff --git a/packages/kovan-faucets/src/ts/server.ts b/packages/kovan-faucets/src/ts/server.ts
new file mode 100644
index 000000000..0ae10e556
--- /dev/null
+++ b/packages/kovan-faucets/src/ts/server.ts
@@ -0,0 +1,27 @@
+import * as bodyParser from 'body-parser';
+import * as express from 'express';
+import {Handler} from './handler';
+import {errorReporter} from './error_reporter';
+
+// Setup the errorReporter to catch uncaught exceptions and unhandled rejections
+errorReporter.setup();
+
+const app = express();
+app.use(bodyParser.json()); // for parsing application/json
+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();
+app.get('/ping', (req: express.Request, res: express.Response) => { res.status(200).send('pong'); });
+app.get('/rain/:recipient', handler.dispenseEther.bind(handler)); // Deprecated gracefully
+app.get('/ether/:recipient', handler.dispenseEther.bind(handler));
+app.get('/zrx/:recipient', handler.dispenseZRX.bind(handler));
+app.get('/queue', handler.getQueueInfo.bind(handler)); // Deprecated gracefully
+
+// Log to rollbar any errors unhandled by handlers
+app.use(errorReporter.errorHandler());
+const port = process.env.PORT || 3000;
+app.listen(port);