fix: Always use IP address for webhooks

This commit is contained in:
Andras Bacsai
2022-04-29 23:02:58 +02:00
parent 8e42203b89
commit 880865f1f2
6 changed files with 39 additions and 16 deletions

View File

@@ -1,3 +1,5 @@
import { dev } from '$app/env';
export const asyncSleep = (delay) => new Promise((resolve) => setTimeout(resolve, delay));
export const dateOptions: DateTimeFormatOptions = {
year: 'numeric',
@@ -21,6 +23,18 @@ export const staticDeployments = [
];
export const notNodeDeployments = ['php', 'docker', 'rust', 'python', 'deno', 'laravel'];
export async function getIP() {
if (dev) {
return 'localhost:3000';
}
const response = await fetch(`https://api.ipify.org?format=json`);
if (response.ok) {
const json = await response.json();
return `http://${json.ip}`;
}
return window.location.origin;
}
export function getDomain(domain) {
return domain?.replace('https://', '').replace('http://', '');
}