added db and list of servers
This commit is contained in:
30
index.js
30
index.js
@@ -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) => {
|
||||
|
||||
Reference in New Issue
Block a user