Skip to content

Commit 0ac940e

Browse files
docs: list all options
1 parent f6822e2 commit 0ac940e

File tree

1 file changed

+122
-0
lines changed

1 file changed

+122
-0
lines changed

README.md

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,128 @@ io.on("connection", (socket) => {
2525
});
2626
```
2727

28+
## Options
29+
30+
### `path`
31+
32+
Default value: `/engine.io/`
33+
34+
It is the name of the path that is captured on the server side.
35+
36+
Caution! The server and the client values must match (unless you are using a
37+
path-rewriting proxy in between).
38+
39+
Example:
40+
41+
```ts
42+
const engine = new Server(httpServer, {
43+
path: "/my-custom-path/",
44+
});
45+
```
46+
47+
### `pingTimeout`
48+
49+
Default value: `20000`
50+
51+
This value is used in the heartbeat mechanism, which periodically checks if the
52+
connection is still alive between the server and the client.
53+
54+
The server sends a ping, and if the client does not answer with a pong within
55+
`pingTimeout` ms, the server considers that the connection is closed.
56+
57+
Similarly, if the client does not receive a ping from the server within
58+
`pingInterval + pingTimeout` ms, the client also considers that the connection
59+
is closed.
60+
61+
### `pingInterval`
62+
63+
Default value: `25000`
64+
65+
See [`pingTimeout`](#pingtimeout) for more explanation.
66+
67+
### `upgradeTimeout`
68+
69+
Default value: `10000`
70+
71+
This is the delay in milliseconds before an uncompleted transport upgrade is
72+
cancelled.
73+
74+
### `maxHttpBufferSize`
75+
76+
Default value: `1e6` (1 MB)
77+
78+
This defines how many bytes a single message can be, before closing the socket.
79+
You may increase or decrease this value depending on your needs.
80+
81+
### `allowRequest`
82+
83+
Default value: `-`
84+
85+
A function that receives a given handshake or upgrade request as its first
86+
parameter, and can decide whether to continue or not.
87+
88+
Example:
89+
90+
```ts
91+
const engine = new Server({
92+
allowRequest: (req, connInfo) => {
93+
return Promise.reject("thou shall not pass");
94+
},
95+
});
96+
```
97+
98+
### `cors`
99+
100+
Default value: `-`
101+
102+
A set of options related to
103+
[Cross-Origin Resource Sharing](https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS)
104+
(CORS).
105+
106+
Example:
107+
108+
```ts
109+
const engine = new Server({
110+
cors: {
111+
origin: ["https://example.com"],
112+
allowedHeaders: ["my-header"],
113+
credentials: true,
114+
},
115+
});
116+
```
117+
118+
### `editHandshakeHeaders`
119+
120+
Default value: `-`
121+
122+
A function that allows to edit the response headers of the handshake request.
123+
124+
Example:
125+
126+
```ts
127+
const engine = new Server({
128+
editHandshakeHeaders: (responseHeaders, req, connInfo) => {
129+
responseHeaders.set("set-cookie", "sid=1234");
130+
},
131+
});
132+
```
133+
134+
### `editResponseHeaders`
135+
136+
Default value: `-`
137+
138+
A function that allows to edit the response headers of all requests.
139+
140+
Example:
141+
142+
```ts
143+
const engine = new Server({
144+
editResponseHeaders: (responseHeaders, req, connInfo) => {
145+
responseHeaders.set("my-header", "abcd");
146+
},
147+
});
148+
```
149+
28150
## License
29151

30152
[MIT](/LICENSE)

0 commit comments

Comments
 (0)