forked from XLNT/local-mobile-foam
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
28 lines (24 loc) · 847 Bytes
/
index.js
File metadata and controls
28 lines (24 loc) · 847 Bytes
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
const Koa = require('koa');
const Router = require('@koa/router');
const bodyParser = require('koa-bodyparser');
const fetch = require('isomorphic-fetch');
const BN = require('bn.js');
const app = new Koa();
const router = new Router();
router.post('/location', async (ctx, next) => {
const res = await fetch(`https://map-api-direct.foam.space/signal/map?${new URLSearchParams(ctx.request.body)}&sort=newest`)
// sort by stake
try {
const data = await res.json();
// for now, just proxy the response back to the client
const sorted = data.sort((a, b) => new BN(a.stake.slice(2), 16).gte(new BN(b.stake.slice(2), 16)));
const first = sorted[0];
ctx.body = first;
} catch (error) {
console.error(error);
}
});
app.use(bodyParser());
app.use(router.routes());
app.use(router.allowedMethods());
app.listen(3000);