mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2025-10-16 12:05:41 +00:00
40 lines
920 B
TypeScript
40 lines
920 B
TypeScript
// Adapted from README
|
|
|
|
// Using with basic http(s) module (example)
|
|
|
|
import http = require("http");
|
|
import * as socketClusterServer from "socketcluster-server";
|
|
|
|
let httpServer = http.createServer();
|
|
let scServer = socketClusterServer.attach(httpServer);
|
|
|
|
scServer.on("connection", socket => {
|
|
// ... Handle new socket connections here
|
|
});
|
|
|
|
httpServer.listen(8000);
|
|
|
|
// Using with Express (example)
|
|
|
|
import serveStatic = require("serve-static");
|
|
import path = require("path");
|
|
import express = require("express");
|
|
|
|
const app = express();
|
|
|
|
app.use(serveStatic(path.resolve(__dirname, "public")));
|
|
|
|
httpServer = http.createServer();
|
|
|
|
// Attach express to our httpServer
|
|
httpServer.on("request", app);
|
|
|
|
// Attach socketcluster-server to our httpServer
|
|
scServer = socketClusterServer.attach(httpServer);
|
|
|
|
scServer.on("connection", socket => {
|
|
// ... Handle new socket connections here
|
|
});
|
|
|
|
httpServer.listen(8000);
|