feat: admin panel + agent.sh download route
This commit is contained in:
@@ -95,8 +95,15 @@ const server = http.createServer((req, res) => {
|
||||
return true;
|
||||
};
|
||||
|
||||
// Static files
|
||||
// Static files + agent.sh download
|
||||
if (method === 'GET' && !url.pathname.startsWith('/api/')) {
|
||||
if (url.pathname === '/agent.sh') {
|
||||
const agentPath = path.join(__dirname, '..', 'agent', 'agent.sh');
|
||||
if (fs.existsSync(agentPath)) {
|
||||
res.writeHead(200, {'Content-Type':'text/plain'});
|
||||
return fs.createReadStream(agentPath).pipe(res);
|
||||
}
|
||||
}
|
||||
let fp = path.join(PUBLIC, url.pathname === '/' ? 'index.html' : url.pathname);
|
||||
if (!fs.existsSync(fp)) fp = path.join(PUBLIC, 'index.html');
|
||||
const ext = path.extname(fp);
|
||||
@@ -154,6 +161,13 @@ const server = http.createServer((req, res) => {
|
||||
return json(200, { ok: true });
|
||||
}
|
||||
|
||||
// GET /api/admin/info
|
||||
if (url.pathname === '/api/admin/info' && method === 'GET') {
|
||||
if (!auth()) return;
|
||||
const nodes = getNodes.all();
|
||||
return json(200, { token: AUTH_TOKEN, nodes });
|
||||
}
|
||||
|
||||
// DELETE /api/node/:id
|
||||
if (url.pathname.startsWith('/api/node/') && method === 'DELETE') {
|
||||
if (!auth()) return;
|
||||
|
||||
Reference in New Issue
Block a user