added db and list of servers

This commit is contained in:
Laptop-Luis
2026-02-16 20:57:40 +01:00
parent 6d41099c39
commit b6c752ce79
9 changed files with 1992 additions and 82 deletions

View File

@@ -3,21 +3,39 @@ const express = require('express');
const app = express();
const bodyParser = require('body-parser');
const path = require('path');
const ping = require('ping')
const ping = require('ping');
const { getDb, getServers, getServerByCol } = require('./dbMgr');
const port = process.env.PORT || 3000;
// Middleware
app.use(bodyParser.json());
app.use(express.static('public'));
// Serve HTML
app.get('/', (req, res) => {
res.sendFile(path.join(__dirname, 'index.html'));
});
// Wake endpoint
app.get('/wake', (req, res) => {
app.get('/api/server/getAll', async (req, res) => {
try {
const db = await getDb()
res.json({ status: 'success', data: await getServers(db) })
} catch (error) {
console.log(error)
res.json({ status: 'error', error: error })
}
})
app.get('/api/server/getAll', async (req, res) => {
try {
const db = await getDb()
res.json({ status: 'success', data: await getServerByCol(db, req.query.col, req.query.val) })
} catch (error) {
console.log(error)
res.json({ status: 'error', error: error })
}
})
app.get('/api/wake', (req, res) => {
const mac = req.query.mac;
if (mac && mac !== '') {
@@ -33,7 +51,7 @@ app.get('/wake', (req, res) => {
}
});
app.get('/ping', (req, res) => {
app.get('/api/ping', (req, res) => {
const host = req.query.host
if(host && host != ''){
ping.sys.probe(host, (isAlive) => {