mirror of
https://github.com/directus/directus.git
synced 2026-04-25 03:00:53 -04:00
Add server service, update returned info
This commit is contained in:
@@ -1,8 +1,14 @@
|
||||
import { Router } from 'express';
|
||||
import ServerService from '../services/server';
|
||||
|
||||
const router = Router();
|
||||
|
||||
router.get('/ping', (req, res) => res.send('pong'));
|
||||
router.get('/info', (req, res) => res.json({ data: process.versions }));
|
||||
|
||||
router.get('/info', (req, res) => {
|
||||
const service = new ServerService({ accountability: req.accountability });
|
||||
const data = service.serverInfo();
|
||||
res.json({ data });
|
||||
});
|
||||
|
||||
export default router;
|
||||
|
||||
39
api/src/services/server.ts
Normal file
39
api/src/services/server.ts
Normal file
@@ -0,0 +1,39 @@
|
||||
import ItemsService from './items';
|
||||
import { AbstractServiceOptions, Accountability } from '../types';
|
||||
import Knex from 'knex';
|
||||
import database from '../database';
|
||||
import os from 'os';
|
||||
import { ForbiddenException } from '../exceptions';
|
||||
import { version } from '../../package.json';
|
||||
|
||||
export default class ServerService {
|
||||
knex: Knex;
|
||||
accountability: Accountability | null;
|
||||
|
||||
constructor(options?: AbstractServiceOptions) {
|
||||
this.knex = options?.knex || database;
|
||||
this.accountability = options?.accountability || null;
|
||||
}
|
||||
|
||||
serverInfo() {
|
||||
if (this.accountability?.admin !== true) {
|
||||
throw new ForbiddenException();
|
||||
}
|
||||
|
||||
return {
|
||||
directus: {
|
||||
version,
|
||||
},
|
||||
node: {
|
||||
version: process.versions.node,
|
||||
uptime: Math.round(process.uptime()),
|
||||
},
|
||||
os: {
|
||||
type: os.type(),
|
||||
version: os.release(),
|
||||
uptime: Math.round(os.uptime()),
|
||||
totalmen: os.totalmem(),
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -11,6 +11,7 @@
|
||||
"lib": [
|
||||
"es2019"
|
||||
],
|
||||
"skipLibCheck": true
|
||||
"skipLibCheck": true,
|
||||
"resolveJsonModule": true,
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user