-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
93 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
# CLI: IPC | ||
|
||
The Unix socket to listen to (instead of a [host](../host-and-port/README.md)). | ||
|
||
## true | ||
|
||
Setting it to `true` will listen to a socket at `/your-os-temp-dir/webpack-dev-server.sock`: | ||
|
||
**webpack.config.js** | ||
|
||
```js | ||
module.exports = { | ||
// ... | ||
devServer: { | ||
ipc: true, | ||
}, | ||
}; | ||
``` | ||
|
||
Usage via CLI: | ||
|
||
```console | ||
npx webpack serve --ipc | ||
``` | ||
|
||
## string | ||
|
||
You can also listen to a different socket with: | ||
|
||
**webpack.config.js** | ||
|
||
```js | ||
const path = require("path"); | ||
|
||
module.exports = { | ||
// ... | ||
devServer: { | ||
ipc: path.join(__dirname, "my-socket.sock"), | ||
}, | ||
}; | ||
``` | ||
|
||
Usage via CLI: | ||
|
||
```console | ||
npx webpack serve --ipc ./my-socket.sock | ||
``` | ||
|
||
## What Should Happen | ||
|
||
1. The script should listen to the socket provided. | ||
1. A proxy server should be created. | ||
1. Go to `http://localhost:8080/`, you should see the text on the page itself change to read `Success!`. |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
"use strict"; | ||
|
||
const http = require("http"); | ||
const httpProxy = require("http-proxy"); | ||
// our setup function adds behind-the-scenes bits to the config that all of our | ||
// examples need | ||
const { setup } = require("../../util"); | ||
|
||
module.exports = setup({ | ||
context: __dirname, | ||
entry: "./app.js", | ||
devServer: { | ||
webSocketServer: "ws", | ||
onAfterSetupMiddleware: (server) => { | ||
const proxyPort = 8080; | ||
const proxyHost = "127.0.0.1"; | ||
const proxy = httpProxy.createProxyServer({ | ||
target: { socketPath: server.options.ipc }, | ||
}); | ||
|
||
const proxyServer = http.createServer((request, response) => { | ||
// You can define here your custom logic to handle the request | ||
// and then proxy the request. | ||
proxy.web(request, response); | ||
}); | ||
|
||
proxyServer.on("upgrade", (request, socket, head) => { | ||
proxy.ws(request, socket, head); | ||
}); | ||
|
||
proxyServer.listen(proxyPort, proxyHost); | ||
}, | ||
}, | ||
}); |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
"use strict"; | ||
|
||
const target = document.querySelector("#target"); | ||
|
||
target.classList.add("pass"); | ||
target.innerHTML = "Success!"; |
File renamed without changes.