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