Skip to content

Commit

Permalink
fix(scully.ts): supprt SSL on kill and launch (#308)
Browse files Browse the repository at this point in the history
* fix(scully.ts): supprt SSL on kill and launch

* fix(ssl support for killserver): ssl supprt for killserver

* fix(httpget): allow unsafe SSL certs on httpGet for self-signed certificates
  • Loading branch information
SanderElias authored Feb 19, 2020
1 parent 550c0c3 commit ab4defa
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
14 changes: 9 additions & 5 deletions scully/scully.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {readFileSync} from 'fs-extra';
import {join} from 'path';
import './pluginManagement/systemPlugins';
import {startBackgroundServer} from './startBackgroundServer';
import {hostName, openNavigator, removeStaticDist, ssl, watch} from './utils/cli-options';
import {loadConfig} from './utils/config';
import {moveDistAngular} from './utils/fsAngular';
import {httpGetJson} from './utils/httpGetJson';
Expand All @@ -15,7 +16,6 @@ import {logError, logWarn, yellow} from './utils/log';
import {startScully} from './utils/startup';
import {waitForServerToBeAvailable} from './utils/waitForServerToBeAvailable';
import {bootServe, isBuildThere, watchMode} from './watchMode';
import {watch, removeStaticDist, openNavigator, hostName} from './utils/cli-options';
const open = require('open');

/** the default of 10 is too shallow for generating pages. */
Expand All @@ -36,7 +36,11 @@ if (process.argv.includes('version')) {
if (process.argv.includes('killServer')) {
await httpGetJson(`https://${scullyConfig.hostName}:${scullyConfig.appPort}/killMe`, {
suppressErrors: true,
});
}).catch(e => e);
await httpGetJson(`https://${scullyConfig.hostName}:${scullyConfig.appPort}/killMe`, {
suppressErrors: true,
}).catch(e => e);
logWarn('Sended kill command to server');
process.exit(0);
return;
}
Expand All @@ -45,7 +49,7 @@ if (process.argv.includes('version')) {
if (process.argv.includes('serve')) {
await bootServe(scullyConfig);
if (openNavigator) {
await open(`https://${scullyConfig.hostName}:${scullyConfig.staticport}/`);
await open(`http${ssl ? 's' : ''}:https://${scullyConfig.hostName}:${scullyConfig.staticport}/`);
}
} else {
const folder = join(scullyConfig.homeFolder, scullyConfig.distFolder);
Expand All @@ -71,7 +75,7 @@ You are using "${yellow(scullyConfig.hostUrl)}" as server.
}
}
if (openNavigator) {
await open(`https://${scullyConfig.hostName}:${scullyConfig.staticport}/`);
await open(`http${ssl ? 's' : ''}:https://${scullyConfig.hostName}:${scullyConfig.staticport}/`);
}
if (watch) {
watchMode(
Expand All @@ -83,7 +87,7 @@ You are using "${yellow(scullyConfig.hostUrl)}" as server.
await startScully();
if (!isTaken && typeof scullyConfig.hostUrl !== 'string') {
// kill serve ports
await httpGetJson(`https://${scullyConfig.hostName}:${scullyConfig.appPort}/killMe`, {
await httpGetJson(`http${ssl ? 's' : ''}:https://${scullyConfig.hostName}:${scullyConfig.appPort}/killMe`, {
suppressErrors: true,
});
}
Expand Down
2 changes: 2 additions & 0 deletions scully/utils/httpGetJson.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ export function httpGetJson(
headers: {},
}
) {
// tslint:disable-next-line:no-string-literal
process.env['NODE_TLS_REJECT_UNAUTHORIZED'] = '0';
const httpGet = url.toLowerCase().includes('https:') ? getHttps : get;
return new Promise((resolve, reject) => {
const {pathname, hostname, port, protocol, search, hash} = new URL(url);
Expand Down
4 changes: 3 additions & 1 deletion scully/utils/staticServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {ssl, tds} from '../utils/cli-options';
import {addSSL} from './addSSL';
import {scullyConfig} from './config';
import {startDataServer} from './dataServer';
import {log, logError, yellow} from './log';
import {log, logError, yellow, logWarn} from './log';
import {proxyAdd} from './proxyAdd';

let angularServerInstance: {close: () => void};
Expand Down Expand Up @@ -51,8 +51,10 @@ export async function staticServer(port?: number) {
res.json({res: true, homeFolder: scullyConfig.homeFolder});
});
angularDistServer.get('/killMe', async (req, res) => {
logWarn('Received Kill command');
await res.json({ok: true});
await closeExpress();
logWarn('Closed servers');
process.exit(0);
});
/** use express to serve all static assets in dist folder. */
Expand Down

0 comments on commit ab4defa

Please sign in to comment.