fix(all): HTTP handler added.

This commit is contained in:
Rodrigo Rodriguez 2023-07-09 08:46:45 -03:00
parent 4823f02bbc
commit 7c6a1753b3
3 changed files with 16 additions and 40 deletions

View file

@ -1,7 +1,7 @@
dist: focal dist: focal
language: node_js language: node_js
node_js: node_js:
- 19.7.0 - 20.3.1
notifications: notifications:

View file

@ -1,6 +1,6 @@
{ {
"name": "botserver", "name": "botserver",
"version": "2.3.9", "version": "3.0.10",
"type": "module", "type": "module",
"description": "General Bot Community Edition open-core server.", "description": "General Bot Community Edition open-core server.",
"main": "./boot.mjs", "main": "./boot.mjs",
@ -15,7 +15,7 @@
"Alan Perdomo <alanperdomo@hotmail.com>" "Alan Perdomo <alanperdomo@hotmail.com>"
], ],
"engines": { "engines": {
"node": "=19.7.0" "node": "=20.3.1"
}, },
"license": "AGPL-3.0", "license": "AGPL-3.0",
"preferGlobal": true, "preferGlobal": true,

View file

@ -39,6 +39,7 @@
import express from 'express'; import express from 'express';
import bodyParser from 'body-parser'; import bodyParser from 'body-parser';
import https from 'https'; import https from 'https';
import http from 'http';
import mkdirp from 'mkdirp'; import mkdirp from 'mkdirp';
import Path from 'path'; import Path from 'path';
import * as Fs from 'fs'; import * as Fs from 'fs';
@ -103,6 +104,17 @@ export class GBServer {
server.use(bodyParser.json()); server.use(bodyParser.json());
server.use(bodyParser.urlencoded({ extended: true })); 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) => { process.on('unhandledRejection', (err, p) => {
GBLog.error(`UNHANDLED_REJECTION(promises): ${err.toString()} ${err['stack'] ? '\n' + err['stack'] : ''}`); GBLog.error(`UNHANDLED_REJECTION(promises): ${err.toString()} ${err['stack'] ? '\n' + err['stack'] : ''}`);
if (err['response']?.obj?.httpStatusCode === 404) { if (err['response']?.obj?.httpStatusCode === 404) {
@ -280,6 +292,7 @@ export class GBServer {
passphrase: process.env.CERTIFICATE_PASSPHRASE, passphrase: process.env.CERTIFICATE_PASSPHRASE,
pfx: Fs.readFileSync(process.env.CERTIFICATE_PFX) pfx: Fs.readFileSync(process.env.CERTIFICATE_PFX)
}; };
const httpsServer = https.createServer(options1, server).listen(port, mainCallback); const httpsServer = https.createServer(options1, server).listen(port, mainCallback);
GBServer.globals.httpsServer = httpsServer; 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);
}
}
------------------------------------------------------------------------------------------
*/