-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
81 lines (68 loc) · 2.81 KB
/
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
const allow_cors = require('cors')();
const http = require('http');
const express = require('express');
const PORT = 8100;
const RunFeature = require('./RunFeature/index.js');
const GetSchedule = require('./GetSchedule/index.js');
const GetToken = require('./GetToken/index.js');
// MIDDLEWARE
const app = express();
app.use(express.json());
app.use(allow_cors);
// ROUTES
/**
* Endpoint returns a JSON payload `{featureUsed:true|false}` indicating whether the feature was used by the back-end.
*
* @param {query:..} req -- request object whereby query should have:
* - 'featureName', see keys in 'feesSchedule.js' -- the gated feature name
* - 'currency', one of 'dollars', 'ethers', 'bitcoins'
* - 'address', ledger specific address
* The header of the request must have an `Authorization` header in the format `Bearer ${token}:${tokenSignature}`.
* - 'token', base64 string containing token to be signed to prove ownership of 'address': will be the token retrieved by `getToken` earlier.
* - 'tokenSignature', base64 string containing signature of 'token', signed by 'from'
* - 'asOf' cache key to make request against back-end quota and not get 429s
* @param {body:..} res -- will contain the response 'res' which is a JSON payload `{featureUsed:true|false}`
* indicating whether the feature was "make-pretend" used by the back-end
*/
app.get('/RunFeature', async (req, res) => {
const context = {};
await RunFeature(context, req);
res.set(context.res.headers);
res.status(context.res.status).send(context.res.body);
});
/**
* Endpoint returns a `{schedule:..}` JSON object that contains the value of `/SharedCode/config.js['fees-schedule']`
*
* @param {query:..} req -- request object, not parsed
* @param {res:..} res -- will contain the response 'res' which is a JSON payload `{schedule:..}`
* which is the fees schedule as per `SharedCode/feesSchedule.js`
*/
app.get('/GetSchedule', async (req, res) => {
const context = {};
await GetSchedule(context, req);
res.set(context.res.headers);
res.status(context.res.status).send(context.res.body);
});
/**
* Endpoint returns a text/plain payload containing the overhide token.
*
* See https://token.overhide.io/swagger.html.
*
* @param {query:..} req -- request object, not parsed
* @param {res:..} res -- will contain the response 'res' which is a text/plain payload containing the overhide token.
*/
app.get('/GetToken', async (req, res) => {
const context = {};
await GetToken(context, req);
res.set(context.res.headers);
res.status(context.res.status).send(context.res.body);
});
// SERVER LIFECYCLE
console.log(`
Available Endpoints:
- http://localhost:${PORT}/GetSchedule
- http://localhost:${PORT}/GetToken
- http://localhost:${PORT}/RunFeature
`);
const server = http.createServer(app);
server.listen(PORT);