*reorder logic to boot up the relay server only after the SSL is ready
This commit is contained in:
parent
573ebec0a4
commit
f89a8e93a4
52
src/relay.ts
52
src/relay.ts
|
@ -52,16 +52,8 @@ export async function start() {
|
|||
router(req, res, next);
|
||||
});
|
||||
|
||||
let httpsServer = https.createServer({
|
||||
SNICallback(servername, cb) {
|
||||
cb(null, sslCtx);
|
||||
},
|
||||
});
|
||||
|
||||
let httpServer = http.createServer(app);
|
||||
|
||||
cron.schedule("0 * * * *", setupSSl.bind(null, false));
|
||||
|
||||
await new Promise((resolve) => {
|
||||
httpServer.listen(80, "0.0.0.0", function () {
|
||||
const address = httpServer.address() as AddressInfo;
|
||||
|
@ -71,23 +63,6 @@ export async function start() {
|
|||
});
|
||||
const dht = await getDHT();
|
||||
|
||||
let wsServer = new WS.Server({ server: httpsServer });
|
||||
|
||||
wsServer.on("connection", (socket: any) => {
|
||||
relay(dht, new Stream(false, socket));
|
||||
});
|
||||
|
||||
await new Promise((resolve) => {
|
||||
httpsServer.listen(relayPort, "0.0.0.0", function () {
|
||||
const address = httpsServer.address() as AddressInfo;
|
||||
log.info(
|
||||
"DHT Relay Server started on ",
|
||||
`${address.address}:${address.port}`
|
||||
);
|
||||
resolve(null);
|
||||
});
|
||||
});
|
||||
|
||||
const statusCodeServer = http.createServer(function (req, res) {
|
||||
// @ts-ignore
|
||||
res.writeHead(req.headers["x-status"] ?? 200, {
|
||||
|
@ -108,6 +83,31 @@ export async function start() {
|
|||
});
|
||||
|
||||
await setupSSl(true);
|
||||
|
||||
let httpsServer = https.createServer({
|
||||
SNICallback(servername, cb) {
|
||||
cb(null, sslCtx);
|
||||
},
|
||||
});
|
||||
|
||||
let wsServer = new WS.Server({ server: httpsServer });
|
||||
|
||||
wsServer.on("connection", (socket: any) => {
|
||||
relay(dht, new Stream(false, socket));
|
||||
});
|
||||
|
||||
await new Promise((resolve) => {
|
||||
httpsServer.listen(relayPort, "0.0.0.0", function () {
|
||||
const address = httpsServer.address() as AddressInfo;
|
||||
log.info(
|
||||
"DHT Relay Server started on ",
|
||||
`${address.address}:${address.port}`
|
||||
);
|
||||
resolve(null);
|
||||
});
|
||||
});
|
||||
|
||||
cron.schedule("0 * * * *", setupSSl.bind(null, false));
|
||||
}
|
||||
|
||||
async function setupSSl(bootup: boolean) {
|
||||
|
@ -130,7 +130,7 @@ async function setupSSl(bootup: boolean) {
|
|||
}, retryOptions);
|
||||
|
||||
await promiseRetry(async (retry: any) => {
|
||||
sslKey = await getSslCert();
|
||||
sslKey = await getSslKey();
|
||||
if (!sslKey) {
|
||||
retry();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue