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); + } + }); + } +}