aboutsummaryrefslogtreecommitdiffstats
path: root/packages/testnet-faucets/src/ts/server.ts
diff options
context:
space:
mode:
authorBrandon Millman <brandon.millman@gmail.com>2018-01-24 02:10:43 +0800
committerBrandon Millman <brandon.millman@gmail.com>2018-01-24 02:10:43 +0800
commitd965fdb11dfba5631c1f98ad3e309876c199999a (patch)
treeec10b7341707cfcc6841d1b5fcbf0d3852536a79 /packages/testnet-faucets/src/ts/server.ts
parent8a858501f2b633f47cec9576b25e6f99911bbc09 (diff)
downloaddexon-0x-contracts-d965fdb11dfba5631c1f98ad3e309876c199999a.tar.gz
dexon-0x-contracts-d965fdb11dfba5631c1f98ad3e309876c199999a.tar.zst
dexon-0x-contracts-d965fdb11dfba5631c1f98ad3e309876c199999a.zip
Rename to testnet-faucets
Diffstat (limited to 'packages/testnet-faucets/src/ts/server.ts')
-rw-r--r--packages/testnet-faucets/src/ts/server.ts28
1 files changed, 28 insertions, 0 deletions
diff --git a/packages/testnet-faucets/src/ts/server.ts b/packages/testnet-faucets/src/ts/server.ts
new file mode 100644
index 000000000..23642787d
--- /dev/null
+++ b/packages/testnet-faucets/src/ts/server.ts
@@ -0,0 +1,28 @@
+import * as bodyParser from 'body-parser';
+import * as express from 'express';
+
+import { errorReporter } from './error_reporter';
+import { Handler } from './handler';
+
+// 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('/ether/:recipient', handler.dispenseEther.bind(handler));
+app.get('/zrx/:recipient', handler.dispenseZRX.bind(handler));
+
+// Log to rollbar any errors unhandled by handlers
+app.use(errorReporter.errorHandler());
+const port = process.env.PORT || 3000;
+app.listen(port);