fix: If DNS not found, do not redirect

This commit is contained in:
Andras Bacsai 2022-02-19 22:37:45 +01:00
parent 15e69c538a
commit cab7ac7d58

View File

@ -1,3 +1,4 @@
import { dev } from '$app/env';
import { getDomain, getUserDetails } from '$lib/common';
import * as db from '$lib/database';
import { listSettings, ErrorHandler } from '$lib/database';
@ -43,7 +44,13 @@ export const del: RequestHandler = async (event) => {
if (status === 401) return { status, body };
const { fqdn } = await event.request.json();
const ip = await dns.resolve(event.url.hostname);
let ip;
console.log(fqdn);
try {
ip = await dns.resolve(fqdn);
} catch (error) {
// Do not care.
}
try {
const domain = getDomain(fqdn);
await db.prisma.setting.update({ where: { fqdn }, data: { fqdn: null } });
@ -53,7 +60,7 @@ export const del: RequestHandler = async (event) => {
status: 200,
body: {
message: 'Domain removed',
redirect: `http://${ip[0]}:3000/settings`
redirect: ip ? `http://${ip[0]}:3000/settings` : undefined
}
};
} catch (error) {