[call-me] - add httpolyglot

This commit is contained in:
Miroslav Pejic
2025-03-22 19:49:07 +01:00
parent 05f0fa024e
commit 7155d6c54a
4 changed files with 18 additions and 35 deletions
+1 -2
View File
@@ -1,7 +1,6 @@
# Server # Server
SSL=false # true or false HOST= # Default http://localhost:port
DOMAIN=localhost
PORT=8000 PORT=8000
# Host # Host
+13 -24
View File
@@ -5,8 +5,7 @@ const dotenv = require('dotenv').config();
const express = require('express'); const express = require('express');
const cors = require('cors'); const cors = require('cors');
const fs = require('fs'); const fs = require('fs');
const http = require('http'); const httpolyglot = require('httpolyglot');
const https = require('https');
const socketIO = require('socket.io'); const socketIO = require('socket.io');
const axios = require('axios'); const axios = require('axios');
const helmet = require('helmet'); const helmet = require('helmet');
@@ -95,32 +94,22 @@ const corsOptions = {
const app = express(); const app = express();
// Server configurations // Server configurations
const domain = process.env.DOMAIN || 'localhost';
const isHttps = process.env.SSL === 'true';
const port = process.env.PORT || 4000; const port = process.env.PORT || 4000;
const host = `http${isHttps ? 's' : ''}://${domain}:${port}`; const host = process.env.HOST || `http://localhost:${port}`;
const apiDocs = host + config.apiBasePath + '/docs'; const apiDocs = host + config.apiBasePath + '/docs';
// This server // Define paths to the SSL key and certificate files
let server; const keyPath = path.join(__dirname, 'ssl/key.pem');
const certPath = path.join(__dirname, 'ssl/cert.pem');
// Load self-signed certificates if HTTPS is enabled // Read SSL key and certificate files securely
if (isHttps) { const options = {
try { key: fs.readFileSync(keyPath, 'utf-8'),
const options = { cert: fs.readFileSync(certPath, 'utf-8'),
key: fs.readFileSync(path.join(__dirname, '/ssl/key.pem'), 'utf-8'), };
cert: fs.readFileSync(path.join(__dirname, '/ssl/cert.pem'), 'utf-8'),
}; // Server both http and https
// Create HTTPS server using Express const server = httpolyglot.createServer(options, app);
server = https.createServer(options, app);
} catch (err) {
log.error('Error loading certificates:', err);
process.exit(1); // Exit the process if certificates cannot be loaded
}
} else {
// Create HTTP server using Express
server = http.createServer(app);
}
// Create WebSocket server using Socket.io on top of HTTP server // Create WebSocket server using Socket.io on top of HTTP server
const io = socketIO(server); const io = socketIO(server);
+1 -7
View File
@@ -2,7 +2,7 @@
![call-me-https](https.png) ![call-me-https](https.png)
1. Generate a [self-signed certificate](https://en.wikipedia.org/wiki/Self-signed_certificate) Generate a [self-signed certificate](https://en.wikipedia.org/wiki/Self-signed_certificate)
```bash ```bash
# install openssl 4 ubuntu # install openssl 4 ubuntu
@@ -19,9 +19,3 @@ rm csr.pem
# https://www.sslchecker.com/certdecoder # https://www.sslchecker.com/certdecoder
``` ```
2. Expose `server.js` on `https` using the `self-signed certificate`, edit the `.env` file
```bash
SSL=true
```
+3 -2
View File
@@ -1,6 +1,6 @@
{ {
"name": "call-me", "name": "call-me",
"version": "1.0.77", "version": "1.0.78",
"description": "Your Go-To for Instant Video Calls", "description": "Your Go-To for Instant Video Calls",
"author": "Miroslav Pejic - miroslav.pejic.85@gmail.com", "author": "Miroslav Pejic - miroslav.pejic.85@gmail.com",
"license": "AGPLv3", "license": "AGPLv3",
@@ -19,12 +19,13 @@
"lint": "npx prettier --write ." "lint": "npx prettier --write ."
}, },
"dependencies": { "dependencies": {
"axios": "^1.8.3", "axios": "^1.8.4",
"colors": "^1.4.0", "colors": "^1.4.0",
"cors": "^2.8.5", "cors": "^2.8.5",
"dotenv": "^16.4.7", "dotenv": "^16.4.7",
"express": "^4.21.2", "express": "^4.21.2",
"helmet": "^8.1.0", "helmet": "^8.1.0",
"httpolyglot": "0.1.2",
"js-yaml": "4.1.0", "js-yaml": "4.1.0",
"socket.io": "^4.8.1", "socket.io": "^4.8.1",
"swagger-ui-express": "5.0.1" "swagger-ui-express": "5.0.1"