This commit is contained in:
Shahrad Elahi
2023-11-06 22:15:58 +03:30
parent 3fa6e3e63e
commit 2f2f0eac39
11 changed files with 444 additions and 25 deletions

View File

@@ -0,0 +1,22 @@
import type { RequestHandler } from '@sveltejs/kit';
import { WG_HOST } from '$env/static/private';
import Shell from '$lib/shell';
export const GET: RequestHandler = async () => {
let HOSTNAME = WG_HOST;
// if the host is not set, then we are using the server's public IP
if (!HOSTNAME) {
const resp = await Shell.exec('curl -s ifconfig.me', true);
HOSTNAME = resp.trim();
}
// check if WG_HOST is still not set
if (!HOSTNAME) {
console.error('WG_HOST is not set');
return new Response('NOT_SET', { status: 500, headers: { 'Content-Type': 'text/plain' } });
}
return new Response(HOSTNAME, { status: 200, headers: { 'Content-Type': 'text/plain' } });
};