Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// Removing ending '/'
if (mount.length > 1 &&
mount[mount.length - 1] === '/') {
mount = mount.slice(0, -1)
}
app.use(mount, ldpApp)
debug.settings('Base URL (--mount): ' + mount)
if (argv.idp) {
console.warn('The idp configuration option has been renamed to multiuser.')
argv.multiuser = argv.idp
delete argv.idp
}
if (argv.httpProxy) {
globalTunnel.initialize(argv.httpProxy)
}
let server
const needsTLS = argv.sslKey || argv.sslCert
if (!needsTLS) {
server = http.createServer(app)
} else {
debug.settings('SSL Private Key path: ' + argv.sslKey)
debug.settings('SSL Certificate path: ' + argv.sslCert)
if (!argv.sslCert && !argv.sslKey) {
throw new Error('Missing SSL cert and SSL key to enable WebIDs')
}
if (!argv.sslKey && argv.sslCert) {
throw new Error('Missing path for SSL key')
#!/usr/bin/env node
'use strict';
require('.')();
// Override http networking to go through a proxy if one is configured.
const MAJOR_NODEJS_VERSION = parseInt(process.version.slice(1).split('.')[0], 10);
if (MAJOR_NODEJS_VERSION >= 10) {
// `global-agent` works with Node.js v10 and above.
require('global-agent').bootstrap();
} else {
// `global-tunnel-ng` works only with Node.js v10 and below.
require('global-tunnel-ng').initialize();
}
function setupProxy() {
var globalAgent = require('global-agent');
var globalTunnel = require('global-tunnel-ng');
var proxyAddress = getProxyAndSetupEnv();
const NODEJS_VERSION = parseInt(process.version.slice(1).split('.')[0], 10);
if (NODEJS_VERSION >= 10 && proxyAddress) {
// `global-agent` works with Node.js v10 and above.
globalAgent.bootstrap();
global.GLOBAL_AGENT.HTTP_PROXY = proxyAddress;
} else {
// `global-tunnel-ng` works only with Node.js v10 and below.
globalTunnel.initialize();
}
}
const list = require('cli-list');
const Tabtab = require('tabtab');
const pkg = require('../package.json');
const Router = require('./router');
const gens = list(process.argv.slice(2));
// Override http networking to go through a proxy ifone is configured
const MAJOR_NODEJS_VERSION = parseInt(process.version.slice(1).split('.')[0], 10);
if (MAJOR_NODEJS_VERSION >= 10) {
// `global-agent` works with Node.js v10 and above.
require('global-agent').bootstrap();
} else {
// `global-tunnel-ng` works only with Node.js v10 and below.
require('global-tunnel-ng').initialize();
}
/* eslint new-cap: 0, no-extra-parens: 0 */
const tabtab = new Tabtab.Commands.default({
name: 'yo',
completer: 'yo-complete'
});
const cli = gens.map(gen => {
const minicli = meow({help: false, pkg, argv: gen});
const opts = minicli.flags;
const args = minicli.input;
// Add un-camelized options too, for legacy
// TODO: Remove some time in the future when generators have upgraded
for (const key of Object.keys(opts)) {
// Doing this before requiring any other modules,
// including the 'balena-sdk', to prevent any module from reading the http proxy config
// before us
const globalTunnel = require('global-tunnel-ng');
const settings = require('balena-settings-client');
let proxy;
try {
proxy = settings.get('proxy') || null;
} catch (error1) {
proxy = null;
}
// Init the tunnel even if the proxy is not configured
// because it can also get the proxy from the http(s)_proxy env var
// If that is not set as well the initialize will do nothing
globalTunnel.initialize(proxy);
// TODO: make this a feature of capitano https://github.com/balena-io/capitano/issues/48
(global as any).PROXY_CONFIG = globalTunnel.proxyConfig;
}
const globalTunnel = require('global-tunnel-ng');
const settings = require('balena-settings-client');
let proxy;
try {
proxy = settings.get('proxy') || null;
} catch (error1) {
proxy = null;
}
// Init the tunnel even if the proxy is not configured
// because it can also get the proxy from the http(s)_proxy env var
// If that is not set as well the initialize will do nothing
globalTunnel.initialize(proxy);
// TODO: make this a feature of capitano https://github.com/balena-io/capitano/issues/48
(global as any).PROXY_CONFIG = globalTunnel.proxyConfig;
}
startProxy(proxy: string) {
if (!proxy) {
return;
}
let proxyConfig: any = urlUtil.parse(proxy);
const {port, hostname, protocol} = proxyConfig;
if (COMMON_CONFIG.proxy.includes(protocol)) {
if (proxyConfig.protocol === COMMON_CONFIG.proxy[0]) {
this.isSocksProxy = true;
} else {
globalTunnel.initialize({
connect: 'both',
host: hostname,
port,
protocol
});
}
} else {
console.log(COMMON_CONFIG.errorText);
process.exit();
}
}
async action(params, options) {
normalizeUuidProp(params);
const proxyConfig = globalTunnel.proxyConfig;
const useProxy = !!proxyConfig && !options.noproxy;
const tunnelViaSocket = (
socket: net.Socket,
host: string,
port: number,
proxyAuth?: Buffer,
): Bluebird =>
new Bluebird((resolve, reject) => {
let tunnelProxyResponse = '';
socket.write(`CONNECT ${host}:${port} HTTP/1.0\r\n`);
if (proxyAuth != null) {
socket.write(
`Proxy-Authorization: Basic ${proxyAuth.toString('base64')}\r\n`,
);
}