Skip to content

Commit

Permalink
Invert logic to manually opting into https
Browse files Browse the repository at this point in the history
This cuts the "generate and trust certificates" step out of the
first-time developer experience.
  • Loading branch information
hobinjk-ptc committed Mar 7, 2024
1 parent 2822f65 commit 7eb3a18
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 11 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/nodejs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ jobs:
run: npm test
env:
CI: true
ALLOW_SECURE_MODE: true

- uses: actions/upload-artifact@v3
if: always()
Expand Down Expand Up @@ -70,7 +71,6 @@ jobs:
run: npm test
env:
CI: true
FORCE_INSECURE_MODE: true

- uses: actions/upload-artifact@v3
if: always()
Expand Down
6 changes: 3 additions & 3 deletions config.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ const argv = yargs
description: 'The port on which udp discovery broadcasts occur (default 52316)',
type: 'number',
})
.option('insecure', {
description: 'Force the server into insecure (http) mode',
.option('secure', {
description: 'Enable the server\'s secure (https) mode',
type: 'boolean',
})
.help()
Expand Down Expand Up @@ -59,4 +59,4 @@ module.exports.beatPort = argv.udpPort || 52316;
// Whether to enable the offline clone functionality
module.exports.persistToCloud = false;

module.exports.forceInsecureMode = argv.insecure || process.env.FORCE_INSECURE_MODE === 'true';
module.exports.allowSecureMode = argv.secure || process.env.ALLOW_SECURE_MODE === 'true';
4 changes: 2 additions & 2 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ try {
}

const _logger = require('./logger');
const {objectsPath, beatPort, forceInsecureMode} = require('./config');
const {objectsPath, beatPort, allowSecureMode} = require('./config');
const {providedServices} = require('./services');

const os = require('os');
Expand All @@ -101,7 +101,7 @@ const globalVariables = {
web: false,
system: false
},
useHTTPS: !forceInsecureMode &&
useHTTPS: allowSecureMode &&
!(isLightweightMobile || isStandaloneMobile) // on mobile devices node.js doesn't fully support HTTPS
};

Expand Down
10 changes: 5 additions & 5 deletions tests/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@ const fs = require('fs');
const path = require('path');
const https = require('https');

const {forceInsecureMode} = require('../config.js');
const {allowSecureMode} = require('../config.js');

const fetch = require('node-fetch');

const fetchAgent = forceInsecureMode ?
null : // No special agent required for http
new https.Agent({rejectUnauthorized: false});
const fetchAgent = allowSecureMode ?
new https.Agent({rejectUnauthorized: false}) :
null; // No special agent required for http
exports.fetchAgent = fetchAgent;

const localProto = forceInsecureMode ? 'http' : 'https';
const localProto = allowSecureMode ? 'https' : 'http';
const localServer = `${localProto}://localhost:8080`;
const localRemoteOperator = `${localProto}://localhost:8081`;

Expand Down

0 comments on commit 7eb3a18

Please sign in to comment.