smollweide / node-mock-server

File based Node REST API mock server
MIT License
254 stars 66 forks source link

Move `protocol` to separate option #76

Closed easingthemes closed 6 years ago

easingthemes commented 6 years ago

When using ssl default http://localhost:3001 is opened.

Currently default options are:

    urlBase: 'http://localhost:3001',
    port: 3001,
    open: true,

If you want to use ssl than https module is used:

if (this.options.privateKey && this.options.certificate) {
    this.server = https.createServer({
  1. But urlBase still has http protocol and that is opened as default:
if (options.open) {
    open(options.urlBase + options.uiPath);
}
  1. Also port is configurable option, but again urlBase stays the same, although I've never saw any issues with this.

Maybe urlBase can be split into protocol, domain and port as configurable options:

const options = {
        ...
    domain:   'localhost',
    port:     3001,
    protocol: 'http'
        ...
}

and than create urlBase from options:

const { protocol, domain, port, urlBase = `${protocol}://${domain}:${port}` } = options;

Simple solution is to use urlBase as https://localhost:3001, so I'm not sure if this is worth implementing or it's quite enough to add this info in readme.

What do you think?

smollweide commented 6 years ago

Your approach is a possible solution but the idea behind baseUrl is to be flexible in case of you are using a host, vm or an docker container.