Skip to content

An open-source, self-hostable PaaS alternative to Vercel, Heroku & Netlify that lets you easily deploy static sites, databases, full-stack applications and 360+ one-click services on your own servers.

Revert "fix: Always use IP address for webhooks"

Andras Bacsaie93d97f2bcc2
diff --git a/src/lib/components/common.ts b/src/lib/components/common.ts
index 78c2d69b7e..d6ff2f8ea0 100644
--- a/src/lib/components/common.ts
+++ b/src/lib/components/common.ts
@@ -1,5 +1,3 @@
-import { dev } from '$app/env';
-
export const asyncSleep = (delay) => new Promise((resolve) => setTimeout(resolve, delay));
export const dateOptions: DateTimeFormatOptions = {
year: 'numeric',
@@ -23,18 +21,6 @@ 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://', '');
}
diff --git a/src/routes/applications/[id]/configuration/_GithubRepositories.svelte b/src/routes/applications/[id]/configuration/_GithubRepositories.svelte
index d59ae3a659..8b5b932cdb 100644
--- a/src/routes/applications/[id]/configuration/_GithubRepositories.svelte
+++ b/src/routes/applications/[id]/configuration/_GithubRepositories.svelte
@@ -8,7 +8,6 @@
import { onMount } from 'svelte';
import { gitTokens } from '$lib/store';
import { t } from '$lib/translations';
- import { getIP } from '$lib/components/common';
const { id } = $page.params;
const from = $page.url.searchParams.get('from');
@@ -114,7 +113,6 @@
}
onMount(async () => {
- const ip = await getIP();
try {
if (!$gitTokens.githubToken) {
const { token } = await get(`/applications/${id}/configuration/githubToken.json`);
@@ -133,7 +131,7 @@
const left = screen.width / 2 - 1020 / 2;
const top = screen.height / 2 - 618 / 2;
const newWindow = open(
- `${htmlUrl}/oauth/authorize?client_id=${application.gitSource.gitlabApp.appId}&redirect_uri=${ip}/webhooks/gitlab&response_type=code&scope=api+email+read_repository&state=${$page.params.id}`,
+ `${htmlUrl}/oauth/authorize?client_id=${application.gitSource.gitlabApp.appId}&redirect_uri=${window.location.origin}/webhooks/gitlab&response_type=code&scope=api+email+read_repository&state=${$page.params.id}`,
'GitLab',
'resizable=1, scrollbars=1, fullscreen=0, height=618, width=1020,top=' +
top +
diff --git a/src/routes/applications/[id]/configuration/_GitlabRepositories.svelte b/src/routes/applications/[id]/configuration/_GitlabRepositories.svelte
index 5159c0945a..a836b3507b 100644
--- a/src/routes/applications/[id]/configuration/_GitlabRepositories.svelte
+++ b/src/routes/applications/[id]/configuration/_GitlabRepositories.svelte
@@ -10,7 +10,6 @@
import { del, get, post, put } from '$lib/api';
import { gitTokens } from '$lib/store';
import { t } from '$lib/translations';
- import { getIP } from '$lib/components/common';
const { id } = $page.params;
const from = $page.url.searchParams.get('from');
@@ -41,7 +40,7 @@
};
onMount(async () => {
if (!$gitTokens.gitlabToken) {
- await getGitlabToken();
+ getGitlabToken();
} else {
loading.base = true;
try {
@@ -50,7 +49,7 @@
});
username = user.username;
} catch (error) {
- return await getGitlabToken();
+ return getGitlabToken();
}
try {
groups = await get(`${apiUrl}/v4/groups?per_page=5000`, {
@@ -65,12 +64,11 @@
}
});
- async function getGitlabToken() {
- const ip = await getIP();
+ function getGitlabToken() {
const left = screen.width / 2 - 1020 / 2;
const top = screen.height / 2 - 618 / 2;
const newWindow = open(
- `${htmlUrl}/oauth/authorize?client_id=${application.gitSource.gitlabApp.appId}&redirect_uri=${ip}/webhooks/gitlab&response_type=code&scope=api+email+read_repository&state=${$page.params.id}`,
+ `${htmlUrl}/oauth/authorize?client_id=${application.gitSource.gitlabApp.appId}&redirect_uri=${window.location.origin}/webhooks/gitlab&response_type=code&scope=api+email+read_repository&state=${$page.params.id}`,
'GitLab',
'resizable=1, scrollbars=1, fullscreen=0, height=618, width=1020,top=' +
top +
@@ -165,10 +163,9 @@
}
}
async function setWebhook(url, webhookToken) {
- const ip = await getIP();
const host = dev
? 'https://webhook.site/0e5beb2c-4e9b-40e2-a89e-32295e570c21'
- : `${ip}/webhooks/gitlab/events`;
+ : `${window.location.origin}/webhooks/gitlab/events`;
try {
await post(
url,
diff --git a/src/routes/applications/[id]/configuration/buildpack.svelte b/src/routes/applications/[id]/configuration/buildpack.svelte
index cb3027854f..7fe2c95ad1 100644
--- a/src/routes/applications/[id]/configuration/buildpack.svelte
+++ b/src/routes/applications/[id]/configuration/buildpack.svelte
@@ -37,7 +37,6 @@
import { gitTokens } from '$lib/store';
import { browser } from '$app/env';
import { t } from '$lib/translations';
- import { getIP } from '$lib/components/common';
const { id } = $page.params;
@@ -175,12 +174,11 @@
error.message === '401 Unauthorized'
) {
if (application.gitSource.gitlabAppId) {
- const ip = await getIP();
let htmlUrl = application.gitSource.htmlUrl;
const left = screen.width / 2 - 1020 / 2;
const top = screen.height / 2 - 618 / 2;
const newWindow = open(
- `${htmlUrl}/oauth/authorize?client_id=${application.gitSource.gitlabApp.appId}&redirect_uri=${ip}/webhooks/gitlab&response_type=code&scope=api+email+read_repository&state=${$page.params.id}`,
+ `${htmlUrl}/oauth/authorize?client_id=${application.gitSource.gitlabApp.appId}&redirect_uri=${window.location.origin}/webhooks/gitlab&response_type=code&scope=api+email+read_repository&state=${$page.params.id}`,
'GitLab',
'resizable=1, scrollbars=1, fullscreen=0, height=618, width=1020,top=' +
top +
diff --git a/src/routes/sources/[id]/_Gitlab.svelte b/src/routes/sources/[id]/_Gitlab.svelte
index 1030e76d80..be1df4909b 100644
--- a/src/routes/sources/[id]/_Gitlab.svelte
+++ b/src/routes/sources/[id]/_Gitlab.svelte
@@ -11,7 +11,6 @@
import { toast } from '@zerodevx/svelte-toast';
import { t } from '$lib/translations';
- import { getIP } from '$lib/components/common';
const { id } = $page.params;
let url = browser ? (settings.fqdn ? settings.fqdn : window.location.origin) : '';
@@ -27,8 +26,7 @@
appSecret: null
};
}
- onMount(async () => {
- url = await getIP();
+ onMount(() => {
oauthIdEl && oauthIdEl.focus();
});
diff --git a/src/routes/sources/[id]/newGithubApp.svelte b/src/routes/sources/[id]/newGithubApp.svelte
index 426208b583..e3215b380b 100644
--- a/src/routes/sources/[id]/newGithubApp.svelte
+++ b/src/routes/sources/[id]/newGithubApp.svelte
@@ -30,21 +30,21 @@
<script>
import { dev } from '$app/env';
- import { getDomain, dashify, getIP } from '$lib/components/common';
+ import { getDomain, dashify } from '$lib/components/common';
import { t } from '$lib/translations';
export let source;
export let settings;
- onMount(async () => {
+ onMount(() => {
const { organization, id, htmlUrl } = source;
const { fqdn } = settings;
- const ip = await getIP();
- let host = `http://${ip}`;
- if (fqdn && fqdn.startsWith('https')) {
- host = `https://${ip}`;
- }
- console.log(ip, host);
+ const host = dev
+ ? 'http://localhost:3000'
+ : fqdn
+ ? fqdn
+ : `http://${window.location.host}` || '';
const domain = getDomain(fqdn);
+
let url = 'settings/apps/new';
if (organization) url = `organizations/${organization}/settings/apps/new`;
const name = dashify(domain) || 'app';