Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
11 changes: 10 additions & 1 deletion docs/scully-cmd-line.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ Scully CLI has the following options available:
- [project](#project)
- [baseFilter](#basefilter)
- [removeStaticDist](#removestaticdist)
- [open](#openNavigator)
- [open](#open)
- [ssl](#ssl)

## serve

Expand Down Expand Up @@ -76,3 +77,11 @@ npx scully serve/watch --open
```

Alias `--o`. Open the default browser and show the scully dist.

## ssl

```bash
npx scully serve/watch --ssl
```

Run the scully server with ssl.
13 changes: 13 additions & 0 deletions scully/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion scully/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
"puppeteer": "^2.0.0",
"yamljs": "^0.3.0",
"yargs": "^14.2.0",
"open": "^7.0.2"
"open": "^7.0.2",
"selfsigned": "^1.10.7"
},
"author": "@herodevs",
"license": "MIT",
Expand Down
5 changes: 5 additions & 0 deletions scully/utils/cli-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,8 @@ export const {openNavigator} = yargs
.alias('o', 'openNavigator')
.alias('open', 'openNavigator')
.describe('o', 'Use this flag for open the browser with the serve').argv;

export const {ssl} = yargs
.boolean('ssl')
.default('ssl', false)
.describe('ssl', 'Add self ssl into the server').argv;
43 changes: 37 additions & 6 deletions scully/utils/staticServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,15 @@ import {join} from 'path';
import {traverseAppRoutes} from '../routerPlugins/traverseAppRoutesPlugin';
import {scullyConfig} from './config';
import {log, logError, yellow} from './log';
import {ssl} from '../utils/cli-options';

const express = require('express');
const https = require('https');
const selfsigned = require('selfsigned');

let angularServerInstance: {close: () => void};
let scullyServerInstance: {close: () => void};
let httpsServer;

export async function staticServer(port?: number) {
try {
Expand All @@ -29,13 +34,36 @@ export async function staticServer(port?: number) {
scullyServer.use(express.static(scullyConfig.outDir, options));
scullyServer.get('/', (req, res) => res.sendFile(join(distFolder, '/index.html')));

scullyServerInstance = scullyServer.listen(port, scullyConfig.hostName, x => {
log(
`Scully static server started on "${yellow(
`http://${scullyConfig.hostName}:${scullyConfig.staticport}/`
)}"`
if (!ssl) {
scullyServerInstance = scullyServer.listen(port, scullyConfig.hostName, x => {
log(
`Scully static server started on "${yellow(
`http://${scullyConfig.hostName}:${scullyConfig.staticport}/`
)}"`
);
});
} else {
const attrs = [
{name: 'scully', value: `${scullyConfig.hostName}:${scullyConfig.staticport}`, type: 'RSAPublicKey'},
];
const pems = selfsigned.generate(attrs, {days: 365});
// serve the API with signed certificate on 443 (SSL/HTTPS) port
httpsServer = https.createServer(
{
key: pems.private,
cert: pems.cert,
},
scullyServer
);
});

httpsServer.listen(port, () => {
log(
`Scully static server started on "${yellow(
`https://${scullyConfig.hostName}:${scullyConfig.staticport}/`
)}"`
);
});
}

const angularDistServer = express();
angularDistServer.get('/_pong', (req, res) => {
Expand Down Expand Up @@ -79,4 +107,7 @@ export function closeExpress() {
if (angularServerInstance && angularServerInstance.close) {
angularServerInstance.close();
}
if (httpsServer) {
httpsServer.close();
}
}