a
This commit is contained in:
parent
6d5bd3e507
commit
121488aab3
|
@ -3,8 +3,6 @@ const cors = require("cors");
|
|||
const fs = require("fs");
|
||||
const https = require("https");
|
||||
const http = require("http");
|
||||
const path = require("path");
|
||||
const ping = require("ping");
|
||||
const status = require("./status/server")
|
||||
|
||||
const app = express();
|
||||
|
@ -16,19 +14,17 @@ const cert = "/etc/letsencrypt/live/blahaj.tr/fullchain.pem"
|
|||
app.use(cors());
|
||||
app.use("/status", status);
|
||||
|
||||
// Try to load SSL Certificates
|
||||
// Try to load certificates
|
||||
try {
|
||||
const sslOptions = {
|
||||
key: fs.readFileSync(key),
|
||||
cert: fs.readFileSync(cert),
|
||||
};
|
||||
|
||||
// Start HTTPS Server if certificates are available
|
||||
https.createServer(sslOptions, app).listen(PORT, () => {
|
||||
console.log(`API running securely at https://localhost:${PORT}`);
|
||||
console.log(`API running at https://localhost:${PORT}`);
|
||||
});
|
||||
} catch (e) {
|
||||
// If certificate loading fails, start HTTP server instead
|
||||
if (e.code === 'ENOENT') {
|
||||
console.warn(`SSL certificate file(s) not found: ${e.path}`);
|
||||
} else {
|
||||
|
@ -37,8 +33,8 @@ try {
|
|||
|
||||
console.log("Starting server without SSL...");
|
||||
|
||||
// Start HTTP Server as fallback
|
||||
// Start http server as fallback
|
||||
http.createServer(app).listen(PORT, () => {
|
||||
console.log(`API running insecurely at http://localhost:${PORT}`);
|
||||
console.log(`API running at http://localhost:${PORT}`);
|
||||
});
|
||||
}
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
const express = require("express");
|
||||
const cors = require("cors");
|
||||
const ping = require("ping");
|
||||
|
||||
const router = express.Router();
|
||||
|
|
Loading…
Reference in a new issue