Create the server running on HTTP and HTTPS #4600
-
Today I have a server with Socket.IO that is only available via HTTPs, that is, even other VMs that are on the same local network, must always connect to the server using the domain. Is it possible to make the same server available both via HTTPs and HTTP? So that via HTTP it is executed by the local IP of the virtual machine by other machines on the same network? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
Hi! You can attach the Socket.IO server to multiple HTTP servers with: import { readFileSync } from "fs";
import * as http from "http";
import * as https from "https";
import { Server } from "socket.io";
const httpServer = http.createServer();
const httpsServer = https.createServer({
key: readFileSync("./key.pem"),
cert: readFileSync("./cert.pem")
});
const io = new Server(httpServer);
httpsServer.on("request", (req, res) => {
io.engine.handleRequest(req, res);
});
httpsServer.on("upgrade", (req, socket, head) => {
io.engine.handleUpgrade(req, socket, head);
});
httpServer.listen(3000)
httpsServer.listen(3001); |
Beta Was this translation helpful? Give feedback.
Hi! You can attach the Socket.IO server to multiple HTTP servers with: