fix(all): HTTP handler added.
This commit is contained in:
parent
4823f02bbc
commit
7c6a1753b3
3 changed files with 16 additions and 40 deletions
|
@ -1,7 +1,7 @@
|
|||
dist: focal
|
||||
language: node_js
|
||||
node_js:
|
||||
- 19.7.0
|
||||
- 20.3.1
|
||||
|
||||
|
||||
notifications:
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "botserver",
|
||||
"version": "2.3.9",
|
||||
"version": "3.0.10",
|
||||
"type": "module",
|
||||
"description": "General Bot Community Edition open-core server.",
|
||||
"main": "./boot.mjs",
|
||||
|
@ -15,7 +15,7 @@
|
|||
"Alan Perdomo <alanperdomo@hotmail.com>"
|
||||
],
|
||||
"engines": {
|
||||
"node": "=19.7.0"
|
||||
"node": "=20.3.1"
|
||||
},
|
||||
"license": "AGPL-3.0",
|
||||
"preferGlobal": true,
|
||||
|
|
50
src/app.ts
50
src/app.ts
|
@ -39,6 +39,7 @@
|
|||
import express from 'express';
|
||||
import bodyParser from 'body-parser';
|
||||
import https from 'https';
|
||||
import http from 'http';
|
||||
import mkdirp from 'mkdirp';
|
||||
import Path from 'path';
|
||||
import * as Fs from 'fs';
|
||||
|
@ -103,6 +104,17 @@ export class GBServer {
|
|||
server.use(bodyParser.json());
|
||||
server.use(bodyParser.urlencoded({ extended: true }));
|
||||
|
||||
// Setups unsecure http redirect.
|
||||
|
||||
server.use(function (request, response, next) {
|
||||
if (process.env.NODE_ENV != 'development' && !request.secure) {
|
||||
return response.redirect("https://" + request.headers.host + request.url);
|
||||
}
|
||||
next();
|
||||
});
|
||||
|
||||
// Setups global error handlers.
|
||||
|
||||
process.on('unhandledRejection', (err, p) => {
|
||||
GBLog.error(`UNHANDLED_REJECTION(promises): ${err.toString()} ${err['stack'] ? '\n' + err['stack'] : ''}`);
|
||||
if (err['response']?.obj?.httpStatusCode === 404) {
|
||||
|
@ -280,6 +292,7 @@ export class GBServer {
|
|||
passphrase: process.env.CERTIFICATE_PASSPHRASE,
|
||||
pfx: Fs.readFileSync(process.env.CERTIFICATE_PFX)
|
||||
};
|
||||
|
||||
const httpsServer = https.createServer(options1, server).listen(port, mainCallback);
|
||||
GBServer.globals.httpsServer = httpsServer;
|
||||
|
||||
|
@ -304,40 +317,3 @@ export class GBServer {
|
|||
}
|
||||
}
|
||||
}
|
||||
/*
|
||||
--------------------------------------------------------------------------------------------
|
||||
if (process.env.CERTIFICATE_PFX) {
|
||||
const options1 = {
|
||||
passphrase: process.env.CERTIFICATE_PASSPHRASE,
|
||||
pfx: Fs.readFileSync(process.env.CERTIFICATE_PFX)
|
||||
};
|
||||
const httpsServer = https.createServer(options1, server).listen(port, mainCallback);
|
||||
GBServer.globals.httpsServer = httpsServer;
|
||||
|
||||
if (process.env.CERTIFICATE2_PFX) {
|
||||
const options2 = {
|
||||
passphrase: process.env.CERTIFICATE2_PASSPHRASE,
|
||||
pfx: Fs.readFileSync(process.env.CERTIFICATE2_PFX)
|
||||
};
|
||||
httpsServer.addContext(process.env.CERTIFICATE2_DOMAIN, options2);
|
||||
}
|
||||
|
||||
if (process.env.CERTIFICATE3_PFX) {
|
||||
const options3 = {
|
||||
passphrase: process.env.CERTIFICATE3_PASSPHRASE,
|
||||
pfx: Fs.readFileSync(process.env.CERTIFICATE3_PFX)
|
||||
};
|
||||
httpsServer.addContext(process.env.CERTIFICATE3_DOMAIN, options3);
|
||||
}
|
||||
|
||||
if (process.env.CERTIFICATE4_PFX) {
|
||||
const options4 = {
|
||||
passphrase: process.env.CERTIFICATE4_PASSPHRASE,
|
||||
pfx: Fs.readFileSync(process.env.CERTIFICATE4_PFX)
|
||||
};
|
||||
httpsServer.addContext(process.env.CERTIFICATE4_DOMAIN, options4);
|
||||
}
|
||||
}
|
||||
------------------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue