Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add an env variable to disable SSL #4

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions api.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ var sessions_settings_object = {
activeDuration: 1000 * 60 * 5, // Extend for five minutes if actively used
cookie: {
httpOnly: true,
secure: true
secure: process.env.SSL_ENABLE === 'true'
}
}
function session_wrapper_function(req, res, next) {
Expand All @@ -48,7 +48,6 @@ async function set_up_api_server(app) {
if (!session_secret_setting) {
console.error(`No session secret is set, can't start API server (this really shouldn't happen...)!`);
throw new Error('NO_SESSION_SECRET_SET');
return
}

const updated_session_settings = {
Expand Down
3 changes: 2 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ services:
# SSL will automatically be set up and
# renewed with LetsEncrypt.
- HOSTNAME=your.host.name
# [REQUIRED] Email for SSL
- SSL_ENABLED=true
# [REQUIRED if SSL_ENABLED] Email for SSL
- [email protected]
# Maximum XSS callback payload size
# This includes the webpage screenshot, DOM HTML,
Expand Down
17 changes: 11 additions & 6 deletions docker-entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
#!/usr/bin/env bash
echo "Initializing SSL/TLS..."
# Set up Greenlock
# Test if --maintainer-email is required, we can set it via environment variables...
npx greenlock init --config-dir /app/greenlock.d --maintainer-email $SSL_CONTACT_EMAIL
npx greenlock add --subject $HOSTNAME --altnames "$HOSTNAME"

if [[ $SSL_ENABLED = 'true' ]]; then
echo "Initializing SSL/TLS..."
# Set up Greenlock
# Test if --maintainer-email is required, we can set it via environment variables...
npx greenlock init --config-dir /app/greenlock.d --maintainer-email $SSL_CONTACT_EMAIL
npx greenlock add --subject $HOSTNAME --altnames "$HOSTNAME"
else
echo "Skipping SSL initialization"
fi

echo "Starting server..."
node server.js
node server.js
20 changes: 13 additions & 7 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const get_app_server = require('./app.js');
const database = require('./database.js');
const database_init = database.database_init;

if(!process.env.SSL_CONTACT_EMAIL) {
if(process.env.SSL_ENABLED === 'true' && !process.env.SSL_CONTACT_EMAIL) {
console.error(`[ERROR] The environment variable 'SSL_CONTACT_EMAIL' is not set, please set it.`);
process.exit();
}
Expand All @@ -16,10 +16,16 @@ if(!process.env.SSL_CONTACT_EMAIL) {

const app = await get_app_server();

require('greenlock-express').init({
packageRoot: __dirname,
configDir: './greenlock.d',
cluster: false,
maintainerEmail: process.env.SSL_CONTACT_EMAIL,
}).serve(app);
if (process.env.SSL_ENABLED !== 'true') {
app.listen(80);
} else {
require("greenlock-express")
.init({
packageRoot: __dirname,
configDir: "./greenlock.d",
cluster: false,
maintainerEmail: process.env.SSL_CONTACT_EMAIL,
})
.serve(app);
}
})();