Skip to content
Merged
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
18 changes: 18 additions & 0 deletions certs/localhost.cert
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
-----BEGIN CERTIFICATE-----
MIIC+zCCAeOgAwIBAgIJAKAmYVmZlyC9MA0GCSqGSIb3DQEBBQUAMBQxEjAQBgNV
BAMMCWxvY2FsaG9zdDAeFw0yMDAyMTIxNTIxMjZaFw0zMDAyMDkxNTIxMjZaMBQx
EjAQBgNVBAMMCWxvY2FsaG9zdDCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoC
ggEBANV/ouk9E2EIBrgN94Y8G6zqjFNNkKYUbB4HdSL/B3eGn1Jkk12XrGQ0af29
WgS5NqKQSXEUDCQexePB8umISGgvhl/JZgzwPIAXGdRj5yLzsCI7jNmrmVHuEpxP
ko6wUID/B76diuGP8RbXtKYlo9qygeHwP28u7Ov+BVQpZsi+Y6XXRwk+JVI+DGdn
fNAkxH1LzSisIAq2xhvRuMIOyBXKuQyhIuXXGcKzmzcZBKodXCrTjiTe7vLySNKw
dwlf0ouCoEQ3JRe5NPG2IR9vRoYw55V6eUszlNGJ9dMeL+8jQ5NKmYUVnZNRuRYe
tWgkkUWKiuA1I1FCVpwUo/D0xsECAwEAAaNQME4wHQYDVR0OBBYEFNDjpi787A7T
zP9Zt0FCeQI2C/vWMB8GA1UdIwQYMBaAFNDjpi787A7TzP9Zt0FCeQI2C/vWMAwG
A1UdEwQFMAMBAf8wDQYJKoZIhvcNAQEFBQADggEBAMiRnVETWJecn/EOnY/0yvrf
A5A1gVYJmOlhu1iLt73xDdAhwDw1FJjb0fbkqABMUmEc5VU2vMB9FTscggU2DrRu
oO73qY3Q7FTo52IH3cYfpIjmV9EN4WbRfHjxVEcvkg+W4UoURebHyJFdAfIORE/8
Y3XBB23lhAgBFiy8H/J5lFFmwRHFiQQpyQ2yE8ok7cKkcsagjnYAthY++OFCaL6D
hTj3dV24Y1p5T2226wYbz34Z0QfnypiW3KGSXMv95ft+2OlVuMTn3CzXyxkgc2fd
YEw3RdI98UosSfYoH3dxvbyFQqKuotaJmTy7BGvTrMs5N9K7fZvf+JJVyCXcKJA=
-----END CERTIFICATE-----
27 changes: 27 additions & 0 deletions certs/localhost.key
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
-----BEGIN RSA PRIVATE KEY-----
MIIEpQIBAAKCAQEA1X+i6T0TYQgGuA33hjwbrOqMU02QphRsHgd1Iv8Hd4afUmST
XZesZDRp/b1aBLk2opBJcRQMJB7F48Hy6YhIaC+GX8lmDPA8gBcZ1GPnIvOwIjuM
2auZUe4SnE+SjrBQgP8Hvp2K4Y/xFte0piWj2rKB4fA/by7s6/4FVClmyL5jpddH
CT4lUj4MZ2d80CTEfUvNKKwgCrbGG9G4wg7IFcq5DKEi5dcZwrObNxkEqh1cKtOO
JN7u8vJI0rB3CV/Si4KgRDclF7k08bYhH29GhjDnlXp5SzOU0Yn10x4v7yNDk0qZ
hRWdk1G5Fh61aCSRRYqK4DUjUUJWnBSj8PTGwQIDAQABAoIBAFoDUT1DCducFbEd
+mE3EHgL/5PTnQvYimjyvfk+Svii4qNLUjJgk0dALfvUDJL3P8i0SrKJQEEuVEKd
b/v0AIsklmPmNsd3thpPIw2//SBoW7djIhRX2/GGDYSnq+PLBHYOkEZWh8pn9L6r
vTdboUTAhDAtKaGHyE4LMFX2iqZRkTJ1lpjbvGEI8O6gfK0KmDbNtOyWbxxpLMl/
V9kGzsfDr6hTtWHnwM4m4twDPMGlJJhq4FxpICurOFFxea/bJUnBvXFr3wCwzc36
GsL07LBtqePnFGlClkEYENXFjG3rbEOWsyVoA0Hn2g99aW8LwaHhrqYZNUe2PRYL
cjQn3j0CgYEA/wM8uyBTJTtqi1Mbkkn1oOLpCmMYmJock+tZDBMIfhfrV6e3SDXr
/qgPTXYtcA3n4xW+PZpAwPbeFE9GyL6BbZJFCPLUlRBAVZX30tPLSf48V19a8UQW
icHb8YLJ4UwaqOZndb2vyFYFUBL/Zb07RgS0oEx2p9dj6B4UQUp77V8CgYEA1lNA
V6a+nBg45BRPqmWBDrT3ua4dNYeh4lZ03QsX9+Yc57VImbJ0qlT3so6oLhqTFXg5
Io6NDXdyjOBXnOrnY61qelqqY8/F5ZFjaOdjLA6Zg36hiMjMIKkrWDWfyXLij4LO
YSPElrrDdLhNrHrOTuEUUfUhHREfrWOswe9Nn98CgYEAxBzZN49EYf2vkjX3nikC
nRfj3/kVkUXzdE4pzP9WKKJ8eoyghwfw1YapPgkEKIiJLDosc3ONGNjBMR1GclsP
bhRuwtL8aSZ2U1thmuEGFYFPJmJOrfyO2KIdYz4RwxGj7wBB0GpwJMEClPIHN1av
nsk/n4cuOSWLz5ZSPWPqqkECgYEArBEEXBpjdyA/NGVWHCAHv83sAGdXze0JO5Rb
mEbaxEw7Mo8pLTPHVCSJBBJh1TnCkf8GJ8c4WPJnxdAqprE0eaL1FCwMFbvuTkMu
Az+ZL/q8poQYnZ9Punz2bogGs42HdN34YKZ9ouFoICIDQhEJ5uvvC2l4X0SrIOIg
BUbhFBMCgYEAwSLgj8dWwwpjOBj2PMAVqPq3O0+SKXPXy5FGFfMi+g0sViCudBSe
QNJpMhHgYeWc+jcqtryQG6lmSSfq4l3A1+ZGDWMwgsg0vkk4O1U9PqkCnzjMeLsd
kvJ0GnJW77//DANnjNSIzp0Eg61QEaQrGMziCSS/ARv8+MHcKQjCzrM=
-----END RSA PRIVATE KEY-----
29 changes: 28 additions & 1 deletion docs/scully-cmd-line.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ Scully CLI has the following options available:
- [project](#project)
- [baseFilter](#basefilter)
- [removeStaticDist](#removestaticdist)
- [open](#openNavigator)
- [open](#open)
- [ssl](#ssl)
- [ssl-cert](#ssl-cert)
- [ssl-key](#ssl-key)

## serve

Expand Down Expand Up @@ -76,3 +79,27 @@ 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.

## ssl-cert

```bash
npx scully serve/watch --ssl --ssl-cert=./url/to/file
```

Add url to ssl cert file for SSL server

## ssl-key

```bash
npx scully serve/watch --ssl --ssl-key=./url/to/file
```

Add url to ssl key file for SSL server
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
"scully:publish:patch": "cd ./scully && tsc -p ./tsconfig.scully.json && npm version patch && cp ./package.json ../dist/scully &&cp ./readme.md ../dist/scully && cd ../dist/scully && npm publish --access=public",
"scully:publish:minor": "tsc -p ./tsconfig.scully.json && npm version minor",
"scully:publish:major": "tsc -p ./tsconfig.scully.json && npm version major",
"scully:test:ssl:self": "npm run generate -- serve --ssl",
"scully:test:ssl:file": "npm run generate -- serve --ssl --ssl-cert=./certs/localhost.cert --ssl-key=./certs/localhost.key",
"commit": "git add . && npx git-cz",
"commit:select": "npx git-cz",
"build-bazel": "bazel build //...",
Expand Down
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
17 changes: 17 additions & 0 deletions scully/utils/cli-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,20 @@ 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;

export const {sslKey} = yargs
.string('sslKey')
.default('sslKey', undefined)
.alias('ssl-key', 'sslKey')
.describe('sslKey', 'Add ssl-key into the server').argv;

export const {sslCert} = yargs
.string('sslCert')
.default('sslCert', undefined)
.alias('ssl-cert', 'sslCert')
.describe('sslCert', 'Add ssl-cert into the server').argv;
66 changes: 59 additions & 7 deletions scully/utils/staticServer.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
import {join} from 'path';
import {traverseAppRoutes} from '../routerPlugins/traverseAppRoutesPlugin';
import {scullyConfig} from './config';
import {log, logError, yellow} from './log';
import {log, logError, red, yellow} from './log';
import {ssl, sslCert, sslKey} from '../utils/cli-options';
import {readFileSync} from 'fs';

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 +35,56 @@ 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 {
let pems = {
private: '',
cert: '',
};
if (sslCert && sslKey) {
try {
pems.private = readFileSync(sslKey).toString();
pems.cert = readFileSync(sslCert).toString();
} catch (e) {
logError(`Could not read the file: ${e.path}`);
log(`${yellow(`Please check the path for the certificate.`)}`);
process.exit(0);
}
} else {
const attrs = [
{
name: 'scully',
value: `${scullyConfig.hostName}:${scullyConfig.staticport}`,
type: 'RSAPublicKey',
},
];
pems = selfsigned.generate(attrs, {days: 365});
console.log(pems);
}
// 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 +128,7 @@ export function closeExpress() {
if (angularServerInstance && angularServerInstance.close) {
angularServerInstance.close();
}
if (httpsServer) {
httpsServer.close();
}
}