Skip to content

Commit

Permalink
CLI port and host options were ignored when connecting
Browse files Browse the repository at this point in the history
  • Loading branch information
dholdren committed Jan 30, 2020
1 parent 07e3edc commit 8721476
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 6 deletions.
26 changes: 20 additions & 6 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ class ServerlessDynamodbLocal {
shortcut: "p",
usage: "The port number that DynamoDB will use to communicate with your application. If you do not specify this option, the default port is 8000"
},
host: {
shortcut: "h",
usage: "The host name that DynamoDB will use to communicate with your application. If you do not specify this option, the default host name is 'localhost'"
},
cors: {
shortcut: "c",
usage: "Enable CORS support (cross-origin resource sharing) for JavaScript. You must provide a comma-separated \"allow\" list of specific domains. The default setting for -cors is an asterisk (*), which allows public access."
Expand Down Expand Up @@ -127,15 +131,25 @@ class ServerlessDynamodbLocal {
}

get port() {
const config = this.service.custom && this.service.custom.dynamodb || {};
const port = _.get(config, "start.port", 8000);
return port;
const config = this.service.custom && this.service.custom.dynamodb || {};
const options = _.merge(
{},
config.start,
this.options
);
const port = options["port"] || 8000;
return port;
}

get host() {
const config = this.service.custom && this.service.custom.dynamodb || {};
const host = _.get(config, "start.host", "localhost");
return host;
const config = this.service.custom && this.service.custom.dynamodb || {};
const options = _.merge(
{},
config.start,
this.options
);
const host = options["host"] || "localhost";
return host;
}

/**
Expand Down
30 changes: 30 additions & 0 deletions test/cliTest.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
"use strict";
//Define the modules required to mocha testing
const assert = require("chai").assert;
const http = require ("http");
const expect = require("chai").expect;
const should = require("should");
const aws = require ("aws-sdk");
const seeder = require("../src/seeder.js");
const Plugin = require("../index.js");

const serverlessMock = require("./serverlessMock");

describe("command line options",function(){
describe("for 'start' command",function(){
let service;
before(function(){
this.timeout(60000);
service = new Plugin(serverlessMock, { port: 8123, host: "home.local" });
//return service.startHandler();
});

it(".port should return cli option",function(){
assert.equal(service.port, 8123);
});

it(".host should return cli option",function(){
assert.equal(service.host, 'home.local');
});
});
});

0 comments on commit 8721476

Please sign in to comment.