Sha256: 9deae4099312a5c2d63af2b0d02635e5d7ed9c110d528dca17ab3c63010e1ad7

Contents?: true

Size: 1.48 KB

Versions: 26

Compression:

Stored size: 1.48 KB

Contents

'use strict';

function getSocketServerImplementation(options) {
  let ServerImplementation;
  let serverImplFound = true;
  switch (typeof options.transportMode.server) {
    case 'string':
      // could be 'sockjs', in the future 'ws', or a path that should be required
      if (options.transportMode.server === 'sockjs') {
        ServerImplementation = require('../servers/SockJSServer');
      } else if (options.transportMode.server === 'ws') {
        ServerImplementation = require('../servers/WebsocketServer');
      } else {
        try {
          // eslint-disable-next-line import/no-dynamic-require
          ServerImplementation = require(options.transportMode.server);
        } catch (e) {
          serverImplFound = false;
        }
      }
      break;
    case 'function':
      // potentially do more checks here to confirm that the user implemented this properlly
      // since errors could be difficult to understand
      ServerImplementation = options.transportMode.server;
      break;
    default:
      serverImplFound = false;
  }

  if (!serverImplFound) {
    throw new Error(
      "transportMode.server must be a string denoting a default implementation (e.g. 'sockjs', 'ws'), a full path to " +
        'a JS file which exports a class extending BaseServer (webpack-dev-server/lib/servers/BaseServer) ' +
        'via require.resolve(...), or the class itself which extends BaseServer'
    );
  }

  return ServerImplementation;
}

module.exports = getSocketServerImplementation;

Version data entries

26 entries across 25 versions & 8 rubygems

Version Path
optimacms-0.1.61 spec/dummy/node_modules/webpack-dev-server/lib/utils/getSocketServerImplementation.js
disco_app-0.18.0 test/dummy/node_modules/webpack-dev-server/lib/utils/getSocketServerImplementation.js
disco_app-0.18.2 test/dummy/node_modules/webpack-dev-server/lib/utils/getSocketServerImplementation.js
disco_app-0.16.1 test/dummy/node_modules/webpack-dev-server/lib/utils/getSocketServerImplementation.js
disco_app-0.15.2 test/dummy/node_modules/webpack-dev-server/lib/utils/getSocketServerImplementation.js
disco_app-0.18.4 test/dummy/node_modules/webpack-dev-server/lib/utils/getSocketServerImplementation.js
disco_app-0.18.1 test/dummy/node_modules/webpack-dev-server/lib/utils/getSocketServerImplementation.js
disco_app-0.12.7.pre.puma.pre.3 test/dummy/node_modules/webpack-dev-server/lib/utils/getSocketServerImplementation.js
disco_app-0.14.0 test/dummy/node_modules/webpack-dev-server/lib/utils/getSocketServerImplementation.js
disco_app-0.13.6.pre.puma.pre.3 test/dummy/node_modules/webpack-dev-server/lib/utils/getSocketServerImplementation.js
tang-0.2.1 spec/tang_app/node_modules/webpack-dev-server/lib/utils/getSocketServerImplementation.js
groonga-client-model-6.0.0 test/apps/rails6.0.3.5/node_modules/webpack-dev-server/lib/utils/getSocketServerImplementation.js
groonga-client-model-6.0.0 test/apps/rails6.1.3/node_modules/webpack-dev-server/lib/utils/getSocketServerImplementation.js
ruby2js-4.0.4 lib/tasks/testrails/node_modules/webpack-dev-server/lib/utils/getSocketServerImplementation.js
ruby2js-4.0.3 lib/tasks/testrails/node_modules/webpack-dev-server/lib/utils/getSocketServerImplementation.js
tang-0.2.0 spec/tang_app/node_modules/webpack-dev-server/lib/utils/getSocketServerImplementation.js
tang-0.1.0 spec/tang_app/node_modules/webpack-dev-server/lib/utils/getSocketServerImplementation.js
tang-0.0.9 spec/tang_app/node_modules/webpack-dev-server/lib/utils/getSocketServerImplementation.js
enju_library-0.3.8 spec/dummy/node_modules/webpack-dev-server/lib/utils/getSocketServerImplementation.js
jester-data-8.0.0 node_modules/webpack-dev-server/lib/utils/getSocketServerImplementation.js