Compare commits
No commits in common. "671c7ad6a11fcdcd4bbc612568a6341d6042031a" and "714da70209f95efcaa939405f062f6ea2eb930da" have entirely different histories.
671c7ad6a1
...
714da70209
|
@ -5,7 +5,7 @@ import * as fs from "fs";
|
|||
import path from "path";
|
||||
import log from "./log.js";
|
||||
|
||||
const config = new Config("lumeweb-relay", "core.confdir");
|
||||
const config = new Config("lumeweb-relay");
|
||||
|
||||
let configDir;
|
||||
|
||||
|
@ -24,11 +24,11 @@ switch (os.platform()) {
|
|||
}
|
||||
|
||||
config.inject({
|
||||
"core.confDir": configDir,
|
||||
"core.confdir": configDir,
|
||||
"core.port": 8080,
|
||||
"core.appPort": 80,
|
||||
"core.logLevel": "info",
|
||||
"core.pluginDir": path.resolve(configDir, "..", "plugins"),
|
||||
"core.apport": 80,
|
||||
"core.loglevel": "info",
|
||||
"core.plugindir": path.resolve(configDir, "..", "plugins"),
|
||||
});
|
||||
|
||||
config.load();
|
||||
|
|
|
@ -7,11 +7,9 @@ import { start as startSwarm, get as getSwarm } from "./modules/swarm.js";
|
|||
import * as bip39 from "@scure/bip39";
|
||||
import { wordlist } from "@scure/bip39/wordlists/english";
|
||||
|
||||
if (!config.str("core.seed")) {
|
||||
if (!config.str("seed")) {
|
||||
config.save("account", {
|
||||
core: {
|
||||
seed: bip39.generateMnemonic(wordlist),
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -4,7 +4,6 @@ import fastify from "fastify";
|
|||
import type { FastifyInstance } from "fastify";
|
||||
import { getKeyPair } from "../lib/seed.js";
|
||||
import config from "../config";
|
||||
import { getPluginAPI } from "./plugin";
|
||||
|
||||
let app: FastifyInstance;
|
||||
|
||||
|
@ -18,13 +17,5 @@ export async function start() {
|
|||
res.send(Buffer.from(keyPair.publicKey).toString("hex"));
|
||||
});
|
||||
|
||||
await getPluginAPI().emitAsync("core.appServer.buildRoutes");
|
||||
|
||||
await app.listen({ port: config.uint("core.appport"), host: "0.0.0.0" });
|
||||
|
||||
getPluginAPI().emit("core.appServer.started");
|
||||
}
|
||||
|
||||
export function get(): FastifyInstance {
|
||||
return app;
|
||||
}
|
||||
|
|
|
@ -17,7 +17,6 @@ import {
|
|||
ProtocolManager,
|
||||
} from "./swarm.js";
|
||||
import { get as getSSl, SSLManager } from "./ssl.js";
|
||||
import { get as getApp } from "./app.js";
|
||||
import type { HDKey } from "micro-ed25519-hdkey";
|
||||
import corePlugins from "../plugins";
|
||||
import Util from "./plugin/util";
|
||||
|
@ -96,10 +95,6 @@ class PluginAPI extends EventEmitter2 {
|
|||
return getProtocolManager();
|
||||
}
|
||||
|
||||
get app() {
|
||||
return getApp();
|
||||
}
|
||||
|
||||
public loadPlugin(
|
||||
moduleName: string
|
||||
): (moduleName: string) => Promise<Plugin> {
|
||||
|
@ -147,39 +142,28 @@ export class PluginAPIManager {
|
|||
}
|
||||
|
||||
let plugin: Plugin;
|
||||
let pluginPath = paths.shift();
|
||||
try {
|
||||
plugin = require(pluginPath as string) as Plugin;
|
||||
plugin = require(paths.shift() as string) as Plugin;
|
||||
} catch (e) {
|
||||
throw e;
|
||||
}
|
||||
|
||||
log.debug("Loaded plugin %s", moduleName);
|
||||
|
||||
const instance = await this.loadPluginInstance(plugin);
|
||||
|
||||
if (!instance) {
|
||||
throw new Error(`Corrupt plugin found at ${pluginPath}`);
|
||||
return this.loadPluginInstance(plugin);
|
||||
}
|
||||
|
||||
return instance as Plugin;
|
||||
}
|
||||
|
||||
public async loadPluginInstance(plugin: Plugin): Promise<Plugin | boolean> {
|
||||
public async loadPluginInstance(plugin: Plugin): Promise<Plugin> {
|
||||
if ("default" in plugin) {
|
||||
plugin = plugin?.default as Plugin;
|
||||
}
|
||||
|
||||
if (!("name" in plugin)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
plugin.name = sanitizeName(plugin.name);
|
||||
|
||||
this.registeredPlugins.set(plugin.name, plugin);
|
||||
|
||||
try {
|
||||
await plugin.plugin(
|
||||
plugin.plugin(
|
||||
// @ts-ignore
|
||||
new Proxy<PluginAPI>(getPluginAPI(), {
|
||||
get(target: PluginAPI, prop: string): any {
|
||||
|
|
|
@ -4,30 +4,24 @@ import log from "../log.js";
|
|||
import config from "../config.js";
|
||||
|
||||
export type SSLManagerRenewHandler = (domain: string) => Promise<boolean>;
|
||||
type SSLCert = string | Buffer | Array<string | Buffer>;
|
||||
|
||||
export class SSLManager {
|
||||
private _key?: Buffer;
|
||||
private _domain: string;
|
||||
|
||||
constructor(domain: string) {
|
||||
this._domain = domain;
|
||||
}
|
||||
|
||||
private _domain: string;
|
||||
|
||||
get domain(): string {
|
||||
return this._domain;
|
||||
}
|
||||
|
||||
private _context?: tls.SecureContext;
|
||||
|
||||
get context(): tls.SecureContext {
|
||||
return this._context as tls.SecureContext;
|
||||
}
|
||||
|
||||
private _cert?: SSLCert;
|
||||
private _cert?: Buffer;
|
||||
|
||||
set cert(cert: SSLCert) {
|
||||
set cert(cert: Buffer) {
|
||||
this._cert = cert;
|
||||
this._maybeUpdateContext();
|
||||
}
|
||||
|
@ -67,21 +61,11 @@ export class SSLManager {
|
|||
}
|
||||
|
||||
private _maybeUpdateContext() {
|
||||
const valid = (value: any) =>
|
||||
b4a.isBuffer(value) || typeof value === "string" || Array.isArray(value);
|
||||
|
||||
if (valid(this._cert) && valid(this._key)) {
|
||||
const opts: tls.SecureContextOptions = {
|
||||
if (b4a.isBuffer(this._cert) && b4a.isBuffer(this._key)) {
|
||||
this._context = tls.createSecureContext({
|
||||
cert: this._cert,
|
||||
key: this._key,
|
||||
};
|
||||
|
||||
if (Array.isArray(this._cert)) {
|
||||
opts.ca = this._cert.slice(1);
|
||||
opts.cert = this._cert[0];
|
||||
} else {
|
||||
opts.cert = this._cert;
|
||||
}
|
||||
this._context = tls.createSecureContext(opts);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -618,13 +618,13 @@ __metadata:
|
|||
|
||||
"@lumeweb/cfg@https://git.lumeweb.com/LumeWeb/cfg.git":
|
||||
version: 0.1.7
|
||||
resolution: "@lumeweb/cfg@https://git.lumeweb.com/LumeWeb/cfg.git#commit=62856686f20c2a627f4bafa92be24ef7f2d49a0d"
|
||||
resolution: "@lumeweb/cfg@https://git.lumeweb.com/LumeWeb/cfg.git#commit=e1d4785240c3815a5b0e376e96e0fb0edfd0c064"
|
||||
dependencies:
|
||||
arg: "npm:^5.0.2"
|
||||
bsert: "npm:~0.0.10"
|
||||
deep-to-flat-object: "npm:^1.0.1"
|
||||
object-path: "npm:^0.11.8"
|
||||
checksum: 5124fda214790212f99fbb6cea6eaf8b6240bbc3c026e1bd4cab9bd441b8be3ccfc2ea1a77cae1fd50d957d1f902f9c955067805d8233168771286e9dacc0d3d
|
||||
checksum: 1b1120ca829d80713b1ed24d3a7827d82fad78c903ce47a0e289bf5799ce791c0e95a967340e83812e290b2749c5c326f4584a6ec33d8dbacaa8d0c04c5291f5
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
|
|
Loading…
Reference in New Issue