source: trip-planner-front/node_modules/webpack-dev-server/lib/utils/getSocketServerImplementation.js@ 8d391a1

Last change on this file since 8d391a1 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 1.5 KB
RevLine 
[6a3a178]1'use strict';
2
3function getSocketServerImplementation(options) {
4 let ServerImplementation;
5 let serverImplFound = true;
6 switch (typeof options.transportMode.server) {
7 case 'string':
8 // could be 'sockjs', in the future 'ws', or a path that should be required
9 if (options.transportMode.server === 'sockjs') {
10 ServerImplementation = require('../servers/SockJSServer');
11 } else if (options.transportMode.server === 'ws') {
12 ServerImplementation = require('../servers/WebsocketServer');
13 } else {
14 try {
15 // eslint-disable-next-line import/no-dynamic-require
16 ServerImplementation = require(options.transportMode.server);
17 } catch (e) {
18 serverImplFound = false;
19 }
20 }
21 break;
22 case 'function':
23 // potentially do more checks here to confirm that the user implemented this properlly
24 // since errors could be difficult to understand
25 ServerImplementation = options.transportMode.server;
26 break;
27 default:
28 serverImplFound = false;
29 }
30
31 if (!serverImplFound) {
32 throw new Error(
33 "transportMode.server must be a string denoting a default implementation (e.g. 'sockjs', 'ws'), a full path to " +
34 'a JS file which exports a class extending BaseServer (webpack-dev-server/lib/servers/BaseServer) ' +
35 'via require.resolve(...), or the class itself which extends BaseServer'
36 );
37 }
38
39 return ServerImplementation;
40}
41
42module.exports = getSocketServerImplementation;
Note: See TracBrowser for help on using the repository browser.