MCPcopy Index your code
hub / github.com/socketio/socket.io / attach

Method attach

lib/index.ts:412–446  ·  view source on GitHub ↗

* Attaches socket.io to a server or port. * * @param srv - server or port * @param opts - options passed to engine.io * @return self

(
    srv: TServerInstance | number,
    opts: Partial<ServerOptions> = {}
  )

Source from the content-addressed store, hash-verified

410 * @return self
411 */
412 public attach(
413 srv: TServerInstance | number,
414 opts: Partial<ServerOptions> = {}
415 ): this {
416 if ("function" == typeof srv) {
417 const msg =
418 "You are trying to attach socket.io to an express " +
419 "request handler function. Please pass a http.Server instance.";
420 throw new Error(msg);
421 }
422
423 // handle a port as a string
424 if (Number(srv) == srv) {
425 srv = Number(srv);
426 }
427
428 if ("number" == typeof srv) {
429 debug("creating http server and binding to %d", srv);
430 const port = srv;
431 srv = http.createServer((req, res) => {
432 res.writeHead(404);
433 res.end();
434 });
435 srv.listen(port);
436 }
437
438 // merge the options passed to the Socket.IO server
439 Object.assign(opts, this.opts);
440 // set engine.io path to `/socket.io`
441 opts.path = opts.path || this._path;
442
443 this.initEngine(srv, opts);
444
445 return this;
446 }
447
448 public attachApp(app /*: TemplatedApp */, opts: Partial<ServerOptions> = {}) {
449 // merge the options passed to the Socket.IO server

Callers 4

constructorMethod · 0.95
listenMethod · 0.95
attachAppMethod · 0.80

Calls 2

initEngineMethod · 0.95
listenMethod · 0.80

Tested by

no test coverage detected