Skip to content

Commit

Permalink
feat: support ssl (#1160)
Browse files Browse the repository at this point in the history
  • Loading branch information
echosoar authored Jul 16, 2021
1 parent 83a64f5 commit 2e442ae
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 2 deletions.
1 change: 1 addition & 0 deletions packages-serverless/serverless-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"node": ">= 10"
},
"files": [
"ssl",
"dist/**/*.js",
"dist/**/*.d.ts",
"index.d.ts"
Expand Down
15 changes: 13 additions & 2 deletions packages-serverless/serverless-app/src/framework.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import * as express from 'express';
import { findNpmModule, output404 } from './utils';
import { start2 } from './start';
import { existsSync, readFileSync } from 'fs';
import { resolve } from 'path';
import { resolve, join } from 'path';
import * as bodyParser from 'body-parser';
import {
getSpecFile,
Expand Down Expand Up @@ -340,7 +340,18 @@ export class Framework

public async run() {
if (this.configurationOptions.port) {
this.server = require('http').createServer(this.app);
if (this.configurationOptions.ssl) {
this.server = require('https').createServer(
{
key: readFileSync(join(__dirname, '../ssl/ssl.key'), 'utf8'),
cert: readFileSync(join(__dirname, '../ssl/ssl.pem'), 'utf8'),
},
this.app
);
} else {
this.server = require('http').createServer(this.app);
}

await new Promise<void>(resolve => {
this.server.listen(this.configurationOptions.port, () => {
resolve();
Expand Down
1 change: 1 addition & 0 deletions packages-serverless/serverless-app/src/interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export interface Application extends FaaSApplication {

export interface IServerlessAppOptions extends IConfigurationOptions {
port?: string | number;
ssl?: boolean;
initContext?: any;
}

Expand Down
27 changes: 27 additions & 0 deletions packages-serverless/serverless-app/ssl/ssl.key
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
-----BEGIN RSA PRIVATE KEY-----
MIIEpAIBAAKCAQEAwYgqylPquhc3d5E75sLxUs7jhxuIfMztx3H449KC7kT9+ukS
bdB/IqwRcLgB/n2V4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GaRw/5l
tzHx10/ERAOK4F+JBnME33NJpYYUOJRpLsfhBtJPt/wagaRJqHMkKgWuevr+E8Bx
7/F3T6BYwEIUHRgCjVDLapECgYEAkkXJaNd6FIFvcL1f/JNd/7FHpueKUpL+NGoM
3XRl0/87R0CY1iE8+iIQplqz0IH8Xm49uxamW9wnFVgnTSBwjed/zdJtT3DppbuG
U69SYhuQd0+CCiK2i05QiFJeox0wn0TkNvzxokW7GCTwIq0dHJ8ZLjCqptK0hjp+
mHSxsckCgYBm/UjNqszQhFr84T3KHZqHr/A/057NlzEILek4Z8QRnlsO26RYVnUI
u/a1E0ZLltD31J9gtR3TuBvbRdphHsHMDf0Jz5wh0h2WCeJ0UcjrspWS6oD0eNI3
dRHiMGdYq3Toz8cmi1AQl63P2f3ICFSVW6d4cA6rOIwBGAB3fX8xKw==
-----END RSA PRIVATE KEY-----
23 changes: 23 additions & 0 deletions packages-serverless/serverless-app/ssl/ssl.pem
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
-----BEGIN CERTIFICATE-----
MIIDzDCCArSgAwIBAgIQLIM+LwmyRiGVIJqA5gR0/TANBgkqhkiG9w0BAQsFADBe
MQswCQYDVQQGEwJDTjEOMAwGA1UEChMFTXlTU0wxKzApBgNVBAsTIk15U1NMIFRl
c3QgUlNBIC0gRm9yIHRlc3QgdXNlIG9ubHkxEjAQBgNVBAMTCU15U1NMLmNvbTAe
Fw0yMTA3MTUxMDAyNDhaFw0yNjA3MTQxMDAyNDhaMBsxCzAJBgNVBAYTAkNOMQww
CgYDVQQDDAMqLiowggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQDBiCrK
U+q6Fzd3kTvmwvFSzuOHG4h8zO3Hcfjj0oLuRP366RJt0H8irBFwuAH+fZXj6mQS
M4cbYr8SseRo53Dsvi1/zA0sxJRsI2WmlhxnoQa5JY1XzQZlEQWJ8q75DeMwRfcr
3qVLmmYGhhAevaKp6O1vVuY33J54jgW46Wb6EdzrMEPzusA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