From f3a200135d7a0d00214d06af42dda2ec2e5d68bb Mon Sep 17 00:00:00 2001 From: tmaslen Date: Wed, 1 Aug 2018 09:41:12 +0100 Subject: [PATCH 1/4] Added basic HTTPS support --- package.json | 2 +- src/Server.js | 12 +++++++++++- src/index.js | 16 ++++++++++++++-- 3 files changed, 26 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index fe5fd9c..a318fa1 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "serverless-local-dev-server", - "version": "0.3.1", + "version": "0.3.2", "engines": { "node": ">=6.10" }, diff --git a/src/Server.js b/src/Server.js index e3a4e60..a31ad10 100644 --- a/src/Server.js +++ b/src/Server.js @@ -16,7 +16,7 @@ class Server { this.processEnvironment = Object.assign({}, process.env) } // Starts the server - start (port) { + start (port, httpsOptions) { if (this.functions.length === 0) { this.log('No Lambdas with Alexa-Skill or HTTP events found') return @@ -45,6 +45,16 @@ class Server { } this.log('----') }) + if ( httpsOptions ) { + const https = require('https'); + const fs = require('fs'); + const options = { + cert: fs.readFileSync(httpsOptions.certPath), + key: fs.readFileSync(httpsOptions.keyPath), + passphrase: httpsOptions.passphrase + } + https.createServer(options, this.app).listen(8443) + } } // Sets functions, including endpoints, using the serverless config and service path setConfiguration (serverlessConfig, servicePath) { diff --git a/src/index.js b/src/index.js index 7efa7e8..0e84743 100644 --- a/src/index.js +++ b/src/index.js @@ -12,7 +12,11 @@ class ServerlessLocalDevServerPlugin { usage: 'Runs a local dev server for Alexa-Skill and HTTP functions', lifecycleEvents: [ 'loadEnvVars', 'start' ], options: { - port: { usage: 'Port to listen on', shortcut: 'p' } + port: { usage: 'Port to listen on', shortcut: 'p' }, + https: { usage: 'Enable HTTPS via port 8443' }, + 'https-cert': { usage: 'Path to cert file to use for HTTPS server' }, + 'https-key': { usage: 'Path to key file to use for HTTPS server' }, + 'https-passphrase': { usage: 'Passphrase for HTTPS server cert file' } } } } @@ -32,7 +36,15 @@ class ServerlessLocalDevServerPlugin { server.log = this.serverless.cli.log.bind(this.serverless.cli) Object.assign(server.customEnvironment, this.options.environment) server.setConfiguration(this.serverless.service, this.serverless.config.servicePath) - server.start(this.options.port || 5005) + let httpsOptions = false; + if ( this.options.https ) { + httpsOptions = { + certPath: this.options[ 'https-cert' ], + keyPath: this.options[ 'https-key' ], + passphrase: this.options[ 'https-passphrase' ] + } + } + server.start(this.options.port || 5005, httpsOptions) } } From 6ed584f851e3032f39b7324c8f5202501f4e0194 Mon Sep 17 00:00:00 2001 From: tmaslen Date: Fri, 3 Aug 2018 10:54:56 +0100 Subject: [PATCH 2/4] Add basic cookie support --- package.json | 2 +- src/endpoints/HttpEndpoint.js | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index a318fa1..b61c22a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "serverless-local-dev-server", - "version": "0.3.2", + "version": "0.3.3", "engines": { "node": ">=6.10" }, diff --git a/src/endpoints/HttpEndpoint.js b/src/endpoints/HttpEndpoint.js index 6ef7291..ac0a9c6 100644 --- a/src/endpoints/HttpEndpoint.js +++ b/src/endpoints/HttpEndpoint.js @@ -18,13 +18,18 @@ class HttpEndpoint extends Endpoint { getLambdaEvent (request) { const pathParameters = request.params || {} const path = this.resourcePath.replace(/:([a-zA-Z_]+)/g, (param) => pathParameters[param.substr(1)]) + let headers = {}; + if ( request.get("Cookie") ) { + headers.Cookie = request.get( "Cookie" ); + } return { httpMethod: request.method, body: JSON.stringify(request.body, null, ' '), queryStringParameters: request.query, pathParameters, path, - resource: this.resource + resource: this.resource, + headers } } handleLambdaSuccess (response, result) { From 195686496cc8c14072d69b1ef9b745a793204a79 Mon Sep 17 00:00:00 2001 From: tmaslen Date: Fri, 3 Aug 2018 10:56:46 +0100 Subject: [PATCH 3/4] Adding request processing express sub module --- package.json | 3 ++- src/Server.js | 2 ++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index b61c22a..43ab625 100644 --- a/package.json +++ b/package.json @@ -30,7 +30,8 @@ "dependencies": { "body-parser": "^1.18.3", "dotenv": "^4.0.0", - "express": "^4.16.3" + "express": "^4.16.3", + "cookie-parser": "^1.4.3" }, "devDependencies": { "chai": "^4.1.2", diff --git a/src/Server.js b/src/Server.js index a31ad10..4d9dab1 100644 --- a/src/Server.js +++ b/src/Server.js @@ -5,6 +5,7 @@ const BodyParser = require('body-parser') const path = require('path') const dotenv = require('dotenv') const getEndpoints = require('./endpoints/get') +const cookieParser = require('cookie-parser') class Server { constructor () { @@ -23,6 +24,7 @@ class Server { } this.app = Express() this.app.use(BodyParser.json()) + this.app.use(cookieParser()) this.functions.forEach(func => func.endpoints.forEach(endpoint => this._attachEndpoint(func, endpoint)) ) From c829ceb823148dfe3ff65904764000e1c37f40e2 Mon Sep 17 00:00:00 2001 From: Tom Maslen Date: Sun, 12 Jul 2020 09:42:28 +0100 Subject: [PATCH 4/4] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 859043a..0b812db 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ Serverless Local Dev Server Plugin (Beta) ======= -[![Build Status](https://travis-ci.org/DieProduktMacher/serverless-local-dev-server.svg?branch=develop)](https://travis-ci.org/DieProduktMacher/serverless-local-dev-server) +DEPRECATED: Please use the official Serverless offline plugin instead: https://www.npmjs.com/package/serverless-offline This plugin exposes Alexa-Skill and HTTP events as local HTTP endpoints, removing the need to deploy every code change to AWS Lambda. You can connect these endpoints to Alexa, Facebook Messenger or other services via forwardhq, ngrok or any other forwarding service.