Files
socket.io/test/support/server.js
Damien Arrachequesne 27de300de4 chore: migrate to rollup
This change allows us to:

- reduce the size of the bundle
- provide an ESM bundle (for usage in <script type="module">)

BREAKING CHANGE: due to how default export works with ES modules, we
have removed the default export of the library, which means the
following code:

```js
require("engine.io-client")(...);
```

will not work anymore. The named export must be used instead:

```js
const { Socket } = require("engine.io-client);
// or import { Socket } from "engine.io-client";

const socket = new Socket(...);
```

Note: the UMD build still exposes a function though:

```html
<script src="/path/to/engine.io.js"></script>
<script>
  const socket = eio(...);
</script>
```

Note: webpack is still used with zuul because of the custom builder
(zuul-builder-webpack)
2021-10-08 11:46:11 +02:00

47 lines
1.2 KiB
JavaScript

// this is a test server to support tests which make requests
const express = require("express");
const app = express();
const join = require("path").join;
const http = require("http").Server(app);
const server = require("engine.io").attach(http, { pingInterval: 500 });
const { rollup } = require("rollup");
const rollupConfig = require("../../support/rollup.config.umd.js");
rollup(rollupConfig).then(async bundle => {
await bundle.write({
...rollupConfig.output[1],
file: "./test/support/public/engine.io.min.js",
sourcemap: false
});
await bundle.close();
});
http.listen(process.env.ZUUL_PORT || 3000);
// serve worker.js and engine.io.js as raw file
app.use("/test/support", express.static(join(__dirname, "public")));
server.on("connection", socket => {
socket.send("hi");
// Bounce any received messages back
socket.on("message", data => {
if (data === "give binary") {
const abv = new Int8Array(5);
for (let i = 0; i < 5; i++) {
abv[i] = i;
}
socket.send(abv);
return;
} else if (data === "give utf8") {
socket.send("пойду спать всем спокойной ночи");
return;
}
socket.send(data);
});
});