Skip to content

Commit

Permalink
#602 Support HTTPS
Browse files Browse the repository at this point in the history
  • Loading branch information
tariqksoliman committed Dec 19, 2024
1 parent 53f00ac commit 23d8e8a
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 1 deletion.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
.env

/node_modules/
/ssl/*
!/ssl/.gitkeep
/API/logs/*
/Missions/*
!/Missions/.gitkeep
Expand Down
12 changes: 12 additions & 0 deletions docs/pages/Setup/ENVs/ENVs.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,18 @@ Password of Postgres database | string | default `null`

Port to run on | positive integer | default `8888`

#### `HTTPS=`

If true, MMGIS will use an https server with the, now required, `HTTPS_KEY` and `HTTPS_CERT` envs. If false, use a wrapping https proxy server instead and block `PORT` from being public | boolean | false

#### `HTTPS_KEY=`

Relative path to key. If using docker, make sure the key is mounted. Everything under 'ssl/' is gitignored.

#### `HTTPS_CERT=`

Relative path to cert. If using docker, make sure the cert is mounted. Everything under 'ssl/' is gitignored.

#### `DB_POOL_MAX=`

Max number connections in the database's pool. CPUs \* 4 is a good number | integer | default `10`
Expand Down
16 changes: 16 additions & 0 deletions sample.env
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,34 @@

# SERVER - node || apache(deprecated)
SERVER=node

# PORT
# In development mode only, PORT+1 will also be used for the main site
PORT=8888

# AUTH - off || none || local || csso
# off: No authentication. Users cannot sign up or log in. Tools that require log in will not work.
# none: No authentication. Users can still sign up and log in from within MMGIS
# local: Anyone without credentials is blocked. The Admin must log in, create accounts and pass out the credentials
# (does not work in dev env/build first and npm run start:prod)
# csso: Use a Cloud Single Sign On service that's proxied in front of MMGIS
AUTH=none

# NODE_ENV - development || production
NODE_ENV=development

# HTTPS - true || false
# If true, MMGIS will use an https server with the, now required, HTTPS_KEY and HTTPS_CERT envs.
# If false, use a wrapping https proxy server instead and block PORT from being public
HTTPS=false

# Relative path to key. If using docker, make sure the key is mounted. Everything under 'ssl/' is gitignored.
HTTPS_KEY='ssl/sample-key.pem'

# Relative path to cert. If using docker, make sure the cert is mounted. Everything under 'ssl/' is gitignored.
HTTPS_CERT='ssl/sample-cert.cert'


# SECRET
SECRET=aSecretKey

Expand Down
12 changes: 11 additions & 1 deletion scripts/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ require("dotenv").config();

const fs = require("fs");
const http = require("http");
const https = require("https");
const { Pool } = require("pg");
var path = require("path");
const packagejson = require("../package.json");
Expand Down Expand Up @@ -881,7 +882,16 @@ setups.getBackendSetups(function (setups) {
//////Setups Init//////
setups.init(s);

const httpServer = http.createServer(app);
let httpServer;
if (process.env.HTTPS == "true") {
httpServer = https.createServer(
{
key: fs.readFileSync("test/fixtures/keys/agent2-key.pem"),
cert: fs.readFileSync("test/fixtures/keys/agent2-cert.cert"),
},
app
);
} else httpServer = http.createServer(app);

// Start listening for requests.
httpServer.listen(port, (err) => {
Expand Down
Empty file added ssl/.gitkeep
Empty file.

0 comments on commit 23d8e8a

Please sign in to comment.