*Restructure to transpile to commonjs since vercel pkg does not support ESM
This commit is contained in:
parent
75afac3de1
commit
0713216cd3
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "@lumeweb/relay",
|
||||
"type": "module",
|
||||
"type": "commonjs",
|
||||
"version": "0.1.0",
|
||||
"description": "",
|
||||
"main": "build/index.js",
|
||||
|
@ -50,6 +50,7 @@
|
|||
"@types/sprintf-js": "^1.1.2",
|
||||
"esbuild": "^0.14.49",
|
||||
"hyper-typings": "^1.0.0",
|
||||
"prettier": "^2.7.1"
|
||||
"prettier": "^2.7.1",
|
||||
"rollup": "^2.77.0"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,11 +1,13 @@
|
|||
//const require = createRequire(import.meta.url);
|
||||
//import { createRequire } from "module";
|
||||
|
||||
// @ts-ignore
|
||||
import BConfig from "bcfg";
|
||||
import * as os from "os";
|
||||
import { createRequire } from "module";
|
||||
|
||||
import path from "path";
|
||||
import { errorExit } from "./error.js";
|
||||
|
||||
const require = createRequire(import.meta.url);
|
||||
const config = new BConfig("lumeweb-relay");
|
||||
|
||||
let configLocation;
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import { createRequire } from "module";
|
||||
//const require = createRequire(import.meta.url);
|
||||
//import { createRequire } from "module";
|
||||
|
||||
const require = createRequire(import.meta.url);
|
||||
const DHT = require("@hyperswarm/dht");
|
||||
import {
|
||||
deriveMyskyRootKeypair,
|
||||
|
|
|
@ -10,8 +10,7 @@ import config from "./config.js";
|
|||
import { hashDataKey } from "@lumeweb/kernel-utils";
|
||||
import { errorExit } from "./error.js";
|
||||
import log from "loglevel";
|
||||
|
||||
const { createHash } = await import("crypto");
|
||||
import { createHash } from "crypto";
|
||||
|
||||
let activeIp: string;
|
||||
|
||||
|
|
|
@ -5,8 +5,10 @@ import config from "./config";
|
|||
|
||||
log.setDefaultLevel(config.str("log-level"));
|
||||
|
||||
await startRpc();
|
||||
await startRelay();
|
||||
async function boot() {
|
||||
await startRpc();
|
||||
await startRelay();
|
||||
}
|
||||
|
||||
process.on("uncaughtException", function (err) {
|
||||
console.log("Caught exception: " + err);
|
||||
|
|
34
src/relay.ts
34
src/relay.ts
|
@ -30,19 +30,14 @@ import { sprintf } from "sprintf-js";
|
|||
let sslCtx: tls.SecureContext = tls.createSecureContext();
|
||||
const sslParams: tls.SecureContextOptions = { cert: "", key: "" };
|
||||
|
||||
const sslPrivateKey = await acme.forge.createPrivateKey();
|
||||
const acmeClient = new acme.Client({
|
||||
accountKey: sslPrivateKey,
|
||||
directoryUrl: isSSlStaging()
|
||||
? acme.directory.letsencrypt.staging
|
||||
: acme.directory.letsencrypt.production,
|
||||
});
|
||||
let acmeClient: acme.Client;
|
||||
|
||||
let app: Express;
|
||||
let router = express.Router();
|
||||
|
||||
const FILE_CERT_NAME = "/lumeweb/relay/ssl.crt";
|
||||
const FILE_KEY_NAME = "/lumeweb/relay/ssl.key";
|
||||
const FILE_ACCOUNT_KEY_NAME = "/lumeweb/relay/account.key";
|
||||
|
||||
type SslData = { crt: IndependentFileSmall; key: IndependentFileSmall };
|
||||
|
||||
|
@ -155,6 +150,30 @@ async function createOrRenewSSl(
|
|||
)
|
||||
);
|
||||
|
||||
let accountKey: boolean | IndependentFileSmall | Buffer = await getSslFile(
|
||||
FILE_ACCOUNT_KEY_NAME
|
||||
);
|
||||
|
||||
if (accountKey) {
|
||||
accountKey = Buffer.from((accountKey as IndependentFileSmall).fileData);
|
||||
}
|
||||
|
||||
if (!accountKey) {
|
||||
accountKey = await acme.forge.createPrivateKey();
|
||||
await createIndependentFileSmall(
|
||||
getSeed(),
|
||||
FILE_ACCOUNT_KEY_NAME,
|
||||
accountKey
|
||||
);
|
||||
}
|
||||
|
||||
acmeClient = new acme.Client({
|
||||
accountKey: accountKey as Buffer,
|
||||
directoryUrl: isSSlStaging()
|
||||
? acme.directory.letsencrypt.staging
|
||||
: acme.directory.letsencrypt.production,
|
||||
});
|
||||
|
||||
const [certificateKey, certificateRequest] = await acme.forge.createCsr({
|
||||
commonName: config.str("domain"),
|
||||
});
|
||||
|
@ -228,6 +247,7 @@ async function getCertInfo() {
|
|||
async function getSslCert(): Promise<IndependentFileSmall | boolean> {
|
||||
return getSslFile(FILE_CERT_NAME);
|
||||
}
|
||||
|
||||
async function getSslKey(): Promise<IndependentFileSmall | boolean> {
|
||||
return getSslFile(FILE_KEY_NAME);
|
||||
}
|
||||
|
|
|
@ -1,8 +1,10 @@
|
|||
//const require = createRequire(import.meta.url);
|
||||
//import { createRequire } from "module";
|
||||
|
||||
import crypto from "crypto";
|
||||
import jayson from "jayson/promise/index.js";
|
||||
import { pack, unpack } from "msgpackr";
|
||||
import { Mutex } from "async-mutex";
|
||||
import { createRequire } from "module";
|
||||
import NodeCache from "node-cache";
|
||||
import { get as getDHT } from "./dht.js";
|
||||
import { rpcMethods } from "./rpc/index.js";
|
||||
|
@ -19,8 +21,6 @@ import {
|
|||
import config, { updateUsePocketGateway, usePocketGateway } from "./config.js";
|
||||
import { ERR_NOT_READY, errorExit } from "./error.js";
|
||||
|
||||
const require = createRequire(import.meta.url);
|
||||
|
||||
const stringify = require("json-stable-stringify");
|
||||
const pendingRequests = new NodeCache();
|
||||
const processedRequests = new NodeCache({
|
||||
|
|
|
@ -1,8 +1,9 @@
|
|||
//import { createRequire } from "module";
|
||||
//const require = createRequire(import.meta.url);
|
||||
|
||||
import { isIp } from "../util.js";
|
||||
import { RpcMethodList } from "./index.js";
|
||||
import { createRequire } from "module";
|
||||
|
||||
const require = createRequire(import.meta.url);
|
||||
const bns = require("bns");
|
||||
const { StubResolver, RecursiveResolver } = bns;
|
||||
|
||||
|
|
|
@ -1,13 +1,14 @@
|
|||
//const require = createRequire(import.meta.url);
|
||||
//import { createRequire } from "module";
|
||||
|
||||
import { RpcMethodList } from "./index.js";
|
||||
// @ts-ignore
|
||||
import rand from "random-key";
|
||||
// @ts-ignore
|
||||
import SPVNode from "hsd/lib/node/spvnode.js";
|
||||
import config from "../config.js";
|
||||
import { createRequire } from "module";
|
||||
import { ERR_NOT_READY } from "../error.js";
|
||||
|
||||
const require = createRequire(import.meta.url);
|
||||
const { NodeClient } = require("hs-client");
|
||||
|
||||
let hsdServer: SPVNode;
|
||||
|
@ -54,15 +55,17 @@ if (!config.bool("hsd-use-external-node")) {
|
|||
}
|
||||
});
|
||||
|
||||
try {
|
||||
await hsdServer.ensure();
|
||||
await hsdServer.open();
|
||||
await hsdServer.connect();
|
||||
(async () => {
|
||||
try {
|
||||
await hsdServer.ensure();
|
||||
await hsdServer.open();
|
||||
await hsdServer.connect();
|
||||
|
||||
hsdServer.startSync();
|
||||
} catch (e: any) {
|
||||
console.error((e as Error).stack);
|
||||
}
|
||||
hsdServer.startSync();
|
||||
} catch (e: any) {
|
||||
console.error((e as Error).stack);
|
||||
}
|
||||
})();
|
||||
} else {
|
||||
clientArgs = {
|
||||
network: config.str("hsd-network-type"),
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import { proxyRpcMethod } from "./common.js";
|
||||
import { RpcMethodList } from "./index.js";
|
||||
import * as chainNetworks from "../networks.json" assert { type: "json" };
|
||||
import * as chainNetworks from "../networks.json";
|
||||
|
||||
export default {
|
||||
getAccountInfo: proxyRpcMethod("getAccountInfo", [
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import * as chainNetworks from "./networks.json" assert { type: "json" };
|
||||
import * as chainNetworks from "./networks.json";
|
||||
|
||||
type networks = { [net: string]: string };
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
{
|
||||
"compilerOptions": {
|
||||
"target": "esnext",
|
||||
"module": "esnext",
|
||||
"target": "es2020",
|
||||
"module": "commonjs",
|
||||
"moduleResolution": "node",
|
||||
"rootDir": "src",
|
||||
"outDir": "build",
|
||||
|
|
Loading…
Reference in New Issue