Skip to content

Create server available on HTTP/HTTPs that can be used with PM2 #4603

Answered by darrachequesne
El-Tommy asked this question in Q&A
Discussion options

You must be logged in to vote

(Edited after rereading the question)

Will I have to make the server available only in HTTP and create a proxy via NGINX to support HTTPs and call the HTTP server?

Yes.

The @socket.io/pm2 package creates its own HTTP server (plain HTTP, listening on port 8080 by default, see here), so it won't work with HTTPS.

For future readers, here is the solution without pm2:

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);

htt…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by darrachequesne
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants