mirror of
https://github.com/wireadmin/wireadmin
synced 2025-06-26 18:28:06 +00:00
feat: dns server
This commit is contained in:
@@ -1,11 +1,12 @@
|
||||
import type { RequestHandler } from '@sveltejs/kit';
|
||||
|
||||
import logger from '@lib/logger';
|
||||
import { getServers, WGServer } from '@lib/wireguard';
|
||||
import { errorBox } from '@lib/logger';
|
||||
import { WG_STORE } from '@lib/storage';
|
||||
import { WGServer } from '@lib/wireguard';
|
||||
|
||||
export const GET: RequestHandler = async () => {
|
||||
try {
|
||||
for (const { id } of await getServers()) {
|
||||
for (const { id } of await WG_STORE.listServers()) {
|
||||
const wg = new WGServer(id);
|
||||
const server = await wg.get();
|
||||
const hasInterface = await wg.isUp();
|
||||
@@ -20,7 +21,7 @@ export const GET: RequestHandler = async () => {
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
logger.error('APIFailed: HealthCheck:', e);
|
||||
errorBox(e);
|
||||
return new Response('FAILED', { status: 500, headers: { 'Content-Type': 'text/plain' } });
|
||||
}
|
||||
|
||||
|
||||
@@ -1,13 +0,0 @@
|
||||
import { json, type RequestHandler } from '@sveltejs/kit';
|
||||
import { execa } from 'execa';
|
||||
|
||||
export const GET: RequestHandler = async ({ params }) => {
|
||||
try {
|
||||
const { stdout } = await execa('screen', ['-ls'], { shell: true });
|
||||
const isRunning = stdout.includes(params.serviceName!);
|
||||
|
||||
return json({ healthy: isRunning });
|
||||
} catch (e) {
|
||||
return json({ healthy: false });
|
||||
}
|
||||
};
|
||||
19
web/src/routes/api/health/[service]/+server.ts
Normal file
19
web/src/routes/api/health/[service]/+server.ts
Normal file
@@ -0,0 +1,19 @@
|
||||
import { json, type RequestHandler } from '@sveltejs/kit';
|
||||
|
||||
import { errorBox } from '@lib/logger';
|
||||
import { getService } from '@lib/services';
|
||||
|
||||
export const GET: RequestHandler = async ({ params }) => {
|
||||
try {
|
||||
const service = getService(params.service);
|
||||
if (!service) {
|
||||
return json({ healthy: false });
|
||||
}
|
||||
const healthy = await service.health();
|
||||
|
||||
return json({ healthy });
|
||||
} catch (e) {
|
||||
errorBox(e);
|
||||
return json({ healthy: false });
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user