diff options
author | Leah Cloudburst <us@conep.one> | 2022-05-23 11:37:56 +0100 |
---|---|---|
committer | Leah Cloudburst <us@conep.one> | 2022-05-23 11:37:56 +0100 |
commit | 7d5a4bafb8c70665961c5729381ed21a4ff22557 (patch) | |
tree | 4a99528b1c84e740748c1d704eb6322d9d48644d | |
parent | 7dfc53595e53658a1964b7cef7d8d16fb2ef8d24 (diff) | |
download | vaportrail-statuspoller-7d5a4bafb8c70665961c5729381ed21a4ff22557.tar.gz vaportrail-statuspoller-7d5a4bafb8c70665961c5729381ed21a4ff22557.tar.bz2 vaportrail-statuspoller-7d5a4bafb8c70665961c5729381ed21a4ff22557.zip |
Add HTTPS support
.dev domains require SSL certs!
-rw-r--r-- | index.ts | 125 |
1 files changed, 66 insertions, 59 deletions
@@ -1,59 +1,66 @@ -import express from "express";
-import si from "systeminformation";
-
-const app = express();
-
-app.get("/json", async (req, res) => {
- // Gives the info for this server
- let cpu = await si.cpu();
- let cpuSpeed = await si.cpuCurrentSpeed();
- let temp = await si.cpuTemperature();
- let memory = await si.mem();
- let os = await si.osInfo();
- let time = si.time();
- let load = await si.currentLoad();
- let processes = await si.processes();
-
- let uptime = parseInt(time.uptime) * 1000;
-
- res.json({
- name: os.hostname,
- cpu: {
- processors: cpu.processors,
- model: `${cpu.manufacturer} ${cpu.brand}`,
- cores: cpu.cores,
- speed: cpuSpeed.avg,
- temperature: temp.main,
- processes: {
- total: processes.all,
- running: processes.running,
- sleeping: processes.sleeping,
- blocked: processes.blocked,
- unknown: processes.unknown
- },
- load: load.currentLoadSystem
- },
- memory: {
- swap: {
- used: memory.swapused,
- free: memory.swapfree,
- total: memory.swaptotal
- },
- physical: {
- used: memory.used,
- free: memory.free,
- total: memory.total
- }
- },
- os: {
- name: os.distro,
- version: os.release
- },
- uptime: uptime,
- version: "1.0.0"
- });
-});
-
-app.listen(52937, () => {
- console.log("Status poller started on polling port (72937).");
-});
+import express from "express"; +import https from "https"; +import { readFileSync } from "fs"; +import si from "systeminformation"; + +var privateKey = readFileSync('./cert/server.key', 'utf8'); +var certificate = readFileSync('./cert/server.crt', 'utf8'); + +var credentials = {key: privateKey, cert: certificate}; + +const app = express(); + +app.get("/json", async (req, res) => { + // Gives the info for this server + let cpu = await si.cpu(); + let cpuSpeed = await si.cpuCurrentSpeed(); + let temp = await si.cpuTemperature(); + let memory = await si.mem(); + let os = await si.osInfo(); + let time = si.time(); + let load = await si.currentLoad(); + let processes = await si.processes(); + + let uptime = parseInt(time.uptime) * 1000; + + res.json({ + name: os.hostname, + cpu: { + processors: cpu.processors, + model: `${cpu.manufacturer} ${cpu.brand}`, + cores: cpu.cores, + speed: cpuSpeed.avg, + temperature: temp.main, + processes: { + total: processes.all, + running: processes.running, + sleeping: processes.sleeping, + blocked: processes.blocked, + unknown: processes.unknown + }, + load: load.currentLoadSystem + }, + memory: { + swap: { + used: memory.swapused, + free: memory.swapfree, + total: memory.swaptotal + }, + physical: { + used: memory.used, + free: memory.free, + total: memory.total + } + }, + os: { + name: os.distro, + version: os.release + }, + uptime: uptime, + version: "1.0.0" + }); +}); + +var httpsServer = https.createServer(credentials, app); + +httpsServer.listen(52937);
\ No newline at end of file |