[call-me] - add httpolyglot
This commit is contained in:
+1
-2
@@ -1,7 +1,6 @@
|
||||
# Server
|
||||
|
||||
SSL=false # true or false
|
||||
DOMAIN=localhost
|
||||
HOST= # Default http://localhost:port
|
||||
PORT=8000
|
||||
|
||||
# Host
|
||||
|
||||
+13
-24
@@ -5,8 +5,7 @@ const dotenv = require('dotenv').config();
|
||||
const express = require('express');
|
||||
const cors = require('cors');
|
||||
const fs = require('fs');
|
||||
const http = require('http');
|
||||
const https = require('https');
|
||||
const httpolyglot = require('httpolyglot');
|
||||
const socketIO = require('socket.io');
|
||||
const axios = require('axios');
|
||||
const helmet = require('helmet');
|
||||
@@ -95,32 +94,22 @@ const corsOptions = {
|
||||
const app = express();
|
||||
|
||||
// Server configurations
|
||||
const domain = process.env.DOMAIN || 'localhost';
|
||||
const isHttps = process.env.SSL === 'true';
|
||||
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';
|
||||
|
||||
// This server
|
||||
let server;
|
||||
// Define paths to the SSL key and certificate files
|
||||
const keyPath = path.join(__dirname, 'ssl/key.pem');
|
||||
const certPath = path.join(__dirname, 'ssl/cert.pem');
|
||||
|
||||
// Load self-signed certificates if HTTPS is enabled
|
||||
if (isHttps) {
|
||||
try {
|
||||
const options = {
|
||||
key: fs.readFileSync(path.join(__dirname, '/ssl/key.pem'), 'utf-8'),
|
||||
cert: fs.readFileSync(path.join(__dirname, '/ssl/cert.pem'), 'utf-8'),
|
||||
};
|
||||
// Create HTTPS server using Express
|
||||
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);
|
||||
}
|
||||
// Read SSL key and certificate files securely
|
||||
const options = {
|
||||
key: fs.readFileSync(keyPath, 'utf-8'),
|
||||
cert: fs.readFileSync(certPath, 'utf-8'),
|
||||
};
|
||||
|
||||
// Server both http and https
|
||||
const server = httpolyglot.createServer(options, app);
|
||||
|
||||
// Create WebSocket server using Socket.io on top of HTTP server
|
||||
const io = socketIO(server);
|
||||
|
||||
+1
-7
@@ -2,7 +2,7 @@
|
||||
|
||||

|
||||
|
||||
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
|
||||
# install openssl 4 ubuntu
|
||||
@@ -19,9 +19,3 @@ rm csr.pem
|
||||
|
||||
# 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
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "call-me",
|
||||
"version": "1.0.77",
|
||||
"version": "1.0.78",
|
||||
"description": "Your Go-To for Instant Video Calls",
|
||||
"author": "Miroslav Pejic - miroslav.pejic.85@gmail.com",
|
||||
"license": "AGPLv3",
|
||||
@@ -19,12 +19,13 @@
|
||||
"lint": "npx prettier --write ."
|
||||
},
|
||||
"dependencies": {
|
||||
"axios": "^1.8.3",
|
||||
"axios": "^1.8.4",
|
||||
"colors": "^1.4.0",
|
||||
"cors": "^2.8.5",
|
||||
"dotenv": "^16.4.7",
|
||||
"express": "^4.21.2",
|
||||
"helmet": "^8.1.0",
|
||||
"httpolyglot": "0.1.2",
|
||||
"js-yaml": "4.1.0",
|
||||
"socket.io": "^4.8.1",
|
||||
"swagger-ui-express": "5.0.1"
|
||||
|
||||
Reference in New Issue
Block a user