Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(server): serverMode 'ws' option #2082

Merged
merged 6 commits into from Jul 5, 2019
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 4 additions & 1 deletion lib/utils/getSocketServerImplementation.js
Expand Up @@ -9,6 +9,9 @@ function getSocketServerImplementation(options) {
if (options.serverMode === 'sockjs') {
// eslint-disable-next-line global-require
ServerImplementation = require('../servers/SockJSServer');
} else if (options.serverMode === 'ws') {
// eslint-disable-next-line global-require
ServerImplementation = require('../servers/WebsocketServer');
} else {
try {
// eslint-disable-next-line global-require, import/no-dynamic-require
Expand All @@ -29,7 +32,7 @@ function getSocketServerImplementation(options) {

if (!serverImplFound) {
throw new Error(
"serverMode must be a string denoting a default implementation (e.g. 'sockjs'), a full path to " +
"serverMode 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'
);
Expand Down
78 changes: 76 additions & 2 deletions test/server/__snapshots__/serverMode-option.test.js.snap
@@ -1,17 +1,91 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`serverMode option with a bad host header results in an error 1`] = `
exports[`serverMode option passed to server with a bad host header results in an error 1`] = `
Array [
"open",
"{\\"type\\":\\"error\\",\\"data\\":\\"Invalid Host/Origin header\\"}",
"close",
]
`;

exports[`serverMode option without a header results in an error 1`] = `
exports[`serverMode option passed to server without a header results in an error 1`] = `
Array [
"open",
"{\\"type\\":\\"error\\",\\"data\\":\\"Invalid Host/Origin header\\"}",
"close",
]
`;

exports[`serverMode option server should close client with bad headers 1`] = `
Array [
Array [
[Function],
],
]
`;

exports[`serverMode option server should close client with bad headers 2`] = `
Array [
Array [
Object {
"foo": "bar",
},
"{\\"type\\":\\"error\\",\\"data\\":\\"Invalid Host/Origin header\\"}",
],
]
`;

exports[`serverMode option server should close client with bad headers 3`] = `
Array [
Array [
Object {
"foo": "bar",
},
],
]
`;

exports[`serverMode option server should use server implementation correctly 1`] = `
Array [
Object {
"foo": "bar",
},
]
`;

exports[`serverMode option server should use server implementation correctly 2`] = `
Array [
Array [
[Function],
],
]
`;

exports[`serverMode option server should use server implementation correctly 3`] = `
Array [
Object {
"foo": "bar",
},
"{\\"type\\":\\"liveReload\\"}",
]
`;

exports[`serverMode option server should use server implementation correctly 4`] = `
Array [
Object {
"foo": "bar",
},
"{\\"type\\":\\"ok\\"}",
]
`;

exports[`serverMode option server should use server implementation correctly 5`] = `
Array [
Array [
Object {
"foo": "bar",
},
[Function],
],
]
`;