mirror of
https://github.com/ringtools/ringtools-server-ts.git
synced 2024-05-16 05:44:40 +02:00
Upgrade dependencies and add socks proxy support
This commit is contained in:
parent
57734b2aab
commit
bf3cf70a63
@ -4,5 +4,8 @@ LND_REST_API_WS=wss://localhost:8080
|
|||||||
LND_REST_API=https://localhost:8080
|
LND_REST_API=https://localhost:8080
|
||||||
REJECT_UNAUTHORIZED=0
|
REJECT_UNAUTHORIZED=0
|
||||||
TLS_CERT_BASE64=ABCD=
|
TLS_CERT_BASE64=ABCD=
|
||||||
|
USE_SOCKS_PROXY=0
|
||||||
|
SOCKS_PROXY_HOST=""
|
||||||
|
SOCKS_PROXY_PORT=1080
|
||||||
#MACAROON_FILE=readonly.macaroon
|
#MACAROON_FILE=readonly.macaroon
|
||||||
#TLS_CERT_FILE=tls.cert
|
#TLS_CERT_FILE=tls.cert
|
@ -29,7 +29,8 @@
|
|||||||
"project": "./tsconfig.json"
|
"project": "./tsconfig.json"
|
||||||
},
|
},
|
||||||
"rules": {
|
"rules": {
|
||||||
"@typescript-eslint/no-unnecessary-condition": "off"
|
"@typescript-eslint/no-unnecessary-condition": "off",
|
||||||
|
"@typescript-eslint/naming-convention": "off"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
|
27
package.json
27
package.json
@ -7,27 +7,28 @@
|
|||||||
"test": "test"
|
"test": "test"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@types/ws": "^8.2.2",
|
"@types/ws": "^8.5.3",
|
||||||
"axios": "^0.24.0",
|
"axios": "^0.26.1",
|
||||||
"dotenv": "12",
|
"dotenv": "16.0.0",
|
||||||
"fastify": "^3.25.3",
|
"fastify": "^3.28.0",
|
||||||
"fastify-cors": "^6.0.2",
|
"fastify-cors": "^6.0.3",
|
||||||
"fastify-decorators": "^3.10.0",
|
"fastify-decorators": "^3.11.0",
|
||||||
"fastify-helmet": "7.0",
|
"fastify-helmet": "7.0.1",
|
||||||
"fastify-plugin": "^3.0.0",
|
"fastify-plugin": "^3.0.1",
|
||||||
"fastify-sensible": "^3.1.2",
|
"fastify-sensible": "^3.1.2",
|
||||||
"fastify-socket.io": "^3.0.0",
|
"fastify-socket.io": "^3.0.0",
|
||||||
"fastify-static": "^4.5.0",
|
"fastify-static": "^4.6.1",
|
||||||
"reflect-metadata": "^0.1.13",
|
"reflect-metadata": "^0.1.13",
|
||||||
"rxjs": "^7.5.2",
|
"rxjs": "^7.5.5",
|
||||||
"socket.io": "^4.4.1",
|
"socket.io": "^4.4.1",
|
||||||
"typescript": "^4.5.4",
|
"socks-proxy-agent": "^6.2.0-beta.0",
|
||||||
"ws": "^8.4.0"
|
"typescript": "^4.6.3",
|
||||||
|
"ws": "^8.5.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@shopify/eslint-plugin": "^41.0.1",
|
"@shopify/eslint-plugin": "^41.0.1",
|
||||||
"@types/jest": "^27.4.0",
|
"@types/jest": "^27.4.0",
|
||||||
"@types/node": "^17.0.8",
|
"@types/node": "^17.0.24",
|
||||||
"@typescript-eslint/eslint-plugin": "^5.8.1",
|
"@typescript-eslint/eslint-plugin": "^5.8.1",
|
||||||
"@typescript-eslint/parser": "^5.8.1",
|
"@typescript-eslint/parser": "^5.8.1",
|
||||||
"axios-mock-adapter": "^1.20.0",
|
"axios-mock-adapter": "^1.20.0",
|
||||||
|
@ -53,8 +53,7 @@ export default class ChannelController {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
return await this.lndService.getChannel(request.params.channelId);
|
return await this.lndService.getChannel(request.params.channelId);
|
||||||
}
|
} catch {
|
||||||
catch {
|
|
||||||
return reply.notFound();
|
return reply.notFound();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
import * as https from 'https';
|
import * as https from 'https';
|
||||||
import {existsSync, readFileSync} from 'fs';
|
import {existsSync, readFileSync} from 'fs';
|
||||||
|
|
||||||
|
import {SocksProxyAgent} from 'socks-proxy-agent';
|
||||||
import axios from 'axios';
|
import axios from 'axios';
|
||||||
import {Subject} from 'rxjs';
|
import {Subject} from 'rxjs';
|
||||||
import WebSocket from 'ws';
|
import WebSocket from 'ws';
|
||||||
@ -23,7 +24,7 @@ if (existsSync(process.env.MACAROON_FILE)) {
|
|||||||
if (existsSync(process.env.TLS_CERT_FILE)) {
|
if (existsSync(process.env.TLS_CERT_FILE)) {
|
||||||
tlsCertData = readFileSync(process.env.TLS_CERT_FILE).toString('ascii');
|
tlsCertData = readFileSync(process.env.TLS_CERT_FILE).toString('ascii');
|
||||||
} else {
|
} else {
|
||||||
const tlsCertData = Buffer.from(
|
tlsCertData = Buffer.from(
|
||||||
process.env.TLS_CERT_BASE64 || '',
|
process.env.TLS_CERT_BASE64 || '',
|
||||||
'base64',
|
'base64',
|
||||||
).toString('ascii');
|
).toString('ascii');
|
||||||
@ -39,20 +40,37 @@ if (process.env.REJECT_UNAUTHORIZED) {
|
|||||||
rejectUnauthorized = Boolean(Number(process.env.REJECT_UNAUTHORIZED));
|
rejectUnauthorized = Boolean(Number(process.env.REJECT_UNAUTHORIZED));
|
||||||
}
|
}
|
||||||
|
|
||||||
const httpsAgent = new https.Agent({
|
let httpsAgent;
|
||||||
|
|
||||||
|
if (process.env.USE_SOCKS_PROXY === '1') {
|
||||||
|
httpsAgent = new SocksProxyAgent({
|
||||||
|
host: process.env.SOCKS_PROXY_HOST || undefined,
|
||||||
|
hostname: process.env.SOCKS_PROXY_HOST || undefined,
|
||||||
|
port: process.env.SOCKS_PROXY_PORT || undefined,
|
||||||
|
tls: {
|
||||||
|
rejectUnauthorized: false,
|
||||||
|
checkServerIdentity: () => undefined,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
httpsAgent = new https.Agent({
|
||||||
rejectUnauthorized,
|
rejectUnauthorized,
|
||||||
ca: tlsCertData,
|
ca: tlsCertData,
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
axios.defaults.httpAgent = httpsAgent;
|
||||||
axios.defaults.httpsAgent = httpsAgent;
|
axios.defaults.httpsAgent = httpsAgent;
|
||||||
|
|
||||||
interface GraphUpdateResult {
|
interface GraphUpdateResult {
|
||||||
result: {
|
error?: {
|
||||||
// eslint-disable-next-line @typescript-eslint/naming-convention
|
code: number;
|
||||||
|
message?: string;
|
||||||
|
details: any;
|
||||||
|
};
|
||||||
|
result?: {
|
||||||
node_updates: [];
|
node_updates: [];
|
||||||
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
||||||
channel_updates: [];
|
channel_updates: [];
|
||||||
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
||||||
closed_chans: [];
|
closed_chans: [];
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@ -82,6 +100,7 @@ export class LndService {
|
|||||||
this.ws = new WebSocket(
|
this.ws = new WebSocket(
|
||||||
`${this.lndRestApiWsUrl}/v1/graph/subscribe?method=GET`,
|
`${this.lndRestApiWsUrl}/v1/graph/subscribe?method=GET`,
|
||||||
{
|
{
|
||||||
|
agent: httpsAgent,
|
||||||
rejectUnauthorized,
|
rejectUnauthorized,
|
||||||
ca: tlsCertData,
|
ca: tlsCertData,
|
||||||
headers: {
|
headers: {
|
||||||
@ -100,9 +119,13 @@ export class LndService {
|
|||||||
this.ws.on('error', (err: Error) => {
|
this.ws.on('error', (err: Error) => {
|
||||||
console.log(`Error: ${err}`);
|
console.log(`Error: ${err}`);
|
||||||
});
|
});
|
||||||
this.ws.on('ping', (event: Buffer) => {});
|
this.ws.on('ping', (_event: Buffer) => {});
|
||||||
this.ws.on('message', (event: WebSocket.RawData) => {
|
this.ws.on('message', (event: WebSocket.RawData) => {
|
||||||
const data: GraphUpdateResult = JSON.parse(event.toString());
|
const data: GraphUpdateResult = JSON.parse(event.toString());
|
||||||
|
if (data.error) {
|
||||||
|
console.log(data.error);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (data.result.node_updates.length) {
|
if (data.result.node_updates.length) {
|
||||||
this.nodeUpdateSubject.next(data.result.node_updates);
|
this.nodeUpdateSubject.next(data.result.node_updates);
|
||||||
|
Loading…
Reference in New Issue
Block a user