From a45f1b66925f3a287222a7b06fd414f6fdd77f3d Mon Sep 17 00:00:00 2001 From: Matthew R Date: Sun, 17 Nov 2019 16:12:00 -0500 Subject: [PATCH] New Root endpoint --- src/api/routes/Root.ts | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 src/api/routes/Root.ts diff --git a/src/api/routes/Root.ts b/src/api/routes/Root.ts new file mode 100644 index 0000000..1401401 --- /dev/null +++ b/src/api/routes/Root.ts @@ -0,0 +1,41 @@ +import os from 'os'; +import { Server } from '..'; +import { Route } from '../../class'; + +export default class Root extends Route { + constructor(server: Server) { + super(server, { path: '/', deprecated: false }); + } + + public bind() { + this.router.get('/', async (req, res) => { + try { + const date = new Date(); + date.setSeconds(-process.uptime()); + const accounts = await this.server.client.db.Account.find(); + const administrators = accounts.filter((account) => account.root === true); + const response = { + nodeVersion: process.version, + uptime: process.uptime(), + server: { + users: accounts.length, + administrators, + }, + stats: { + uptime: os.uptime(), + loadAverage: os.loadavg(), + cpuModel: os.cpus()[0].model, + cpuClock: os.cpus()[0].speed / 1000, + cpuCores: os.cpus().length, + hostname: os.hostname(), + ipv4: os.networkInterfaces().eth0.filter((r) => r.family === 'IPv4')[0].address, + ipv6: os.networkInterfaces().eth0.filter((r) => r.family === 'IPv6')[0].address, + }, + }; + res.status(200).json({ code: this.constants.codes.SUCCESS, message: response }); + } catch (error) { + this.handleError(error, res); + } + }); + } +}