Skip to content

Commit

Permalink
fix(all): HTTP handler added.
Browse files Browse the repository at this point in the history
  • Loading branch information
rodrigorodriguez committed Jul 9, 2023
1 parent 4823f02 commit 7c6a175
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 40 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
dist: focal
language: node_js
node_js:
- 19.7.0
- 20.3.1


notifications:
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand All @@ -15,7 +15,7 @@
"Alan Perdomo <alanperdomo@hotmail.com>"
],
"engines": {
"node": "=19.7.0"
"node": "=20.3.1"
},
"license": "AGPL-3.0",
"preferGlobal": true,
Expand Down
50 changes: 13 additions & 37 deletions src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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;

Expand All @@ -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);
}
}
------------------------------------------------------------------------------------------
*/

0 comments on commit 7c6a175

Please sign in to comment.