Skip to content
Open
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -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.

Expand Down
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "serverless-local-dev-server",
"version": "0.3.1",
"version": "0.3.3",
"engines": {
"node": ">=6.10"
},
Expand Down Expand Up @@ -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",
Expand Down
14 changes: 13 additions & 1 deletion src/Server.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand All @@ -16,13 +17,14 @@ 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
}
this.app = Express()
this.app.use(BodyParser.json())
this.app.use(cookieParser())
this.functions.forEach(func =>
func.endpoints.forEach(endpoint => this._attachEndpoint(func, endpoint))
)
Expand All @@ -45,6 +47,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) {
Expand Down
7 changes: 6 additions & 1 deletion src/endpoints/HttpEndpoint.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
16 changes: 14 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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' }
}
}
}
Expand All @@ -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)
}
}

Expand Down