Skip to content

Commit

Permalink
feat: Allow custom servers to be injected.
Browse files Browse the repository at this point in the history
  • Loading branch information
EdwardSalter committed Apr 5, 2021
1 parent 5c87eb2 commit b909180
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions lib/open-api-mocker.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,15 @@ class OpenApiMocker {
return 5000;
}

constructor({ port, server = 'express' }) {
// eslint-disable-next-line global-require, import/no-dynamic-require
const Server = require(`./mocker/${server}/server`);

this.server = new Server();
constructor({ port, server }) {
// Legacy handling of string based server that loads a server implementation based on folder name
if(typeof server === 'string' || server == null) {
// eslint-disable-next-line global-require, import/no-dynamic-require
const Server = require(`./mocker/${server || 'express'}/server`);
server = new Server();
}

this.server = server;
this.port = port || this.constructor.defaultPort;
}

Expand Down

0 comments on commit b909180

Please sign in to comment.