Skip to content

Commit

Permalink
[CI mode, ember-cli test] enabling WebSocket proxying
Browse files Browse the repository at this point in the history
simple patch leveraging WebSocket proxying capabilities of
http-proxy by an entry identifying itself as "ws: true" in the testem.json/testem.js
'proxies' section
(cf. https://github.com/testem/testem?tab=readme-ov-file#api-proxy):

…
  "proxies": {
    …
    "/mywsendpoint": {
      …
      ws: true
    },
    …
  }

Works with ember-cli test, offering equivalent functionality to ember-cli server --proxy=… in CI testing mode.
  • Loading branch information
IBue authored and IBue committed Feb 12, 2024
1 parent f2bc5cc commit 5b14762
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions lib/server/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -217,10 +217,17 @@ class Server extends EventEmitter {
this.proxy = new httpProxy.createProxyServer({changeOrigin: true});

this.proxy.on('error', (err, req, res) => {
res.status(500).json(err);
res?.status(500).json(err);
});

Object.keys(proxies).forEach(url => {
Object.keys(proxies).forEach((url) => {
if (proxies[url].ws === true) {
this.server.on('upgrade', (req, socket, head) => {
if (req.url.startsWith(url)) {
this.proxy.ws(req, socket, head, proxies[url]);
}
});
}
app.all(`${url}*`, (req, res, next) => {
var opts = proxies[url];
if (this.shouldProxy(req, opts)) {
Expand Down

0 comments on commit 5b14762

Please sign in to comment.