2021-04-11 01:53:16 -04:00
|
|
|
// process.env.DEBUG = 'xyz:valnet:*';
|
2021-04-08 20:38:05 -04:00
|
|
|
|
2020-11-13 10:19:44 -05:00
|
|
|
(async () => {
|
2021-04-11 01:53:16 -04:00
|
|
|
const { title } = require('../src/lib/title');
|
2021-04-01 15:06:22 -04:00
|
|
|
const log = require('signale').scope('RLAY');
|
2021-04-11 01:53:16 -04:00
|
|
|
const { Identity } = require('../src/lib/Identity');
|
2020-11-11 22:06:45 -05:00
|
|
|
title('relay', false);
|
2021-04-11 01:53:16 -04:00
|
|
|
const Node = require('../src/lib/node');
|
|
|
|
|
const { config } = require('../src/lib/config');
|
2021-04-01 23:01:24 -04:00
|
|
|
const { ensureDirSync } = require('fs-extra');
|
2021-04-11 01:53:16 -04:00
|
|
|
const appdata = require('../src/lib/appdata');
|
2021-04-01 01:04:17 -04:00
|
|
|
|
2021-04-01 23:01:24 -04:00
|
|
|
ensureDirSync(`${appdata}/valnet/relay`);
|
2021-04-08 22:02:58 -04:00
|
|
|
const node = new Node();
|
2021-02-13 23:56:20 -05:00
|
|
|
|
2020-11-13 10:19:44 -05:00
|
|
|
// ==================================== [EXPRESS]
|
2020-11-11 22:21:35 -05:00
|
|
|
const express = require('express');
|
|
|
|
|
const app = express();
|
2020-11-11 21:47:54 -05:00
|
|
|
|
2020-11-11 22:21:35 -05:00
|
|
|
app.get('/', (req, res) => {
|
2020-11-18 11:18:39 -05:00
|
|
|
res.end(`
|
2021-02-13 23:56:20 -05:00
|
|
|
<table style="min-width: 300px">
|
2020-11-18 11:18:39 -05:00
|
|
|
<tr>
|
2021-02-13 23:56:20 -05:00
|
|
|
<th>Id</th>
|
|
|
|
|
<th>Address</th>
|
|
|
|
|
<th>loopback</th>
|
2020-11-18 11:18:39 -05:00
|
|
|
</tr>
|
2021-02-13 23:56:20 -05:00
|
|
|
${clients.map((client, index) => `
|
|
|
|
|
<tr>
|
|
|
|
|
<td><pre>${index}</pre></td>
|
|
|
|
|
<td><pre>${client.remoteAddress}</pre></td>
|
|
|
|
|
<td><pre>${client.loopback}</pre></td>
|
|
|
|
|
</tr>
|
|
|
|
|
`).join('')}
|
2020-11-18 11:18:39 -05:00
|
|
|
</table>
|
|
|
|
|
`);
|
2020-11-18 12:02:58 -05:00
|
|
|
});
|
|
|
|
|
|
2021-02-15 09:30:56 -05:00
|
|
|
app.use((req, res, next) => {
|
|
|
|
|
res.header('Access-Control-Allow-Origin', '*');
|
|
|
|
|
next();
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
app.get('/clients', (req, res) => {
|
|
|
|
|
res.json({
|
|
|
|
|
clients: clients.map((client, index) => {
|
|
|
|
|
return {
|
|
|
|
|
id: index,
|
|
|
|
|
address: client.remoteAddress,
|
|
|
|
|
loopback: client.loopback,
|
|
|
|
|
identity: client.identity.publicKey,
|
|
|
|
|
connected: client.secured
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
})
|
2020-11-18 12:02:58 -05:00
|
|
|
// app.post
|
2020-11-11 22:21:35 -05:00
|
|
|
|
2021-02-14 02:21:35 -05:00
|
|
|
app.listen(config.ports.http).on('error', e => {
|
2021-02-14 02:03:26 -05:00
|
|
|
log.warn(e);
|
|
|
|
|
setTimeout(_ => {
|
2021-02-14 02:21:35 -05:00
|
|
|
app.listen(config.ports.http).on('error', e => {
|
2021-02-14 02:03:26 -05:00
|
|
|
log.error(e);
|
|
|
|
|
});
|
2021-02-14 02:21:35 -05:00
|
|
|
}, config.ports.http);
|
2021-02-14 02:03:26 -05:00
|
|
|
});
|
2020-11-13 10:19:44 -05:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
})();
|