feat: Gitpod integration
This commit is contained in:
parent
002637ec5f
commit
9f9d4297ca
@ -15,7 +15,7 @@ import { checkContainer, getEngine, removeContainer } from './docker';
|
||||
import { day } from './dayjs';
|
||||
import * as serviceFields from './serviceFields'
|
||||
|
||||
export const version = '3.1.0';
|
||||
export const version = '3.2.0';
|
||||
export const isDev = process.env.NODE_ENV === 'development';
|
||||
|
||||
const algorithm = 'aes-256-ctr';
|
||||
@ -30,13 +30,29 @@ export const defaultProxyImage = `coolify-haproxy-alpine:latest`;
|
||||
export const defaultProxyImageTcp = `coolify-haproxy-tcp-alpine:latest`;
|
||||
export const defaultProxyImageHttp = `coolify-haproxy-http-alpine:latest`;
|
||||
export const defaultTraefikImage = `traefik:v2.6`;
|
||||
export function getAPIUrl() {
|
||||
if (process.env.GITPOD_WORKSPACE_URL) {
|
||||
const { href } = new URL(process.env.GITPOD_WORKSPACE_URL)
|
||||
const newURL = href.replace('https://', 'https://3001-').replace(/\/$/, '')
|
||||
return newURL
|
||||
}
|
||||
return isDev ? 'http://localhost:3001' : 'http://localhost:3000';
|
||||
}
|
||||
export function getUIUrl() {
|
||||
if (process.env.GITPOD_WORKSPACE_URL) {
|
||||
const { href } = new URL(process.env.GITPOD_WORKSPACE_URL)
|
||||
const newURL = href.replace('https://', 'https://3000-').replace(/\/$/, '')
|
||||
return newURL
|
||||
}
|
||||
return 'http://localhost:3000';
|
||||
}
|
||||
|
||||
const mainTraefikEndpoint = isDev
|
||||
? 'http://host.docker.internal:3001/webhooks/traefik/main.json'
|
||||
? `${getAPIUrl()}/webhooks/traefik/main.json`
|
||||
: 'http://coolify:3000/webhooks/traefik/main.json';
|
||||
|
||||
const otherTraefikEndpoint = isDev
|
||||
? 'http://host.docker.internal:3001/webhooks/traefik/other.json'
|
||||
? `${getAPIUrl()}/webhooks/traefik/other.json`
|
||||
: 'http://coolify:3000/webhooks/traefik/other.json';
|
||||
|
||||
|
||||
|
@ -2,7 +2,7 @@ import axios from "axios";
|
||||
import cuid from "cuid";
|
||||
import crypto from "crypto";
|
||||
import type { FastifyReply, FastifyRequest } from "fastify";
|
||||
import { encrypt, errorHandler, isDev, prisma } from "../../../lib/common";
|
||||
import { encrypt, errorHandler, getAPIUrl, getUIUrl, isDev, prisma } from "../../../lib/common";
|
||||
import { checkContainer, removeContainer } from "../../../lib/docker";
|
||||
import { scheduler } from "../../../lib/scheduler";
|
||||
import { getApplicationFromDB, getApplicationFromDBWebhook } from "../../api/v1/applications/handlers";
|
||||
@ -19,7 +19,7 @@ export async function installGithub(request: FastifyRequest, reply: FastifyReply
|
||||
data: { installationId: Number(installation_id) }
|
||||
});
|
||||
if (isDev) {
|
||||
return reply.redirect(`http://localhost:3000/sources/${gitSourceId}`)
|
||||
return reply.redirect(`${getUIUrl()}/sources/${gitSourceId}`)
|
||||
} else {
|
||||
return reply.redirect(`/sources/${gitSourceId}`)
|
||||
}
|
||||
@ -55,7 +55,7 @@ export async function configureGitHubApp(request, reply) {
|
||||
}
|
||||
});
|
||||
if (isDev) {
|
||||
return reply.redirect(`http://localhost:3000/sources/${state}`)
|
||||
return reply.redirect(`${getUIUrl()}/sources/${state}`)
|
||||
} else {
|
||||
return reply.redirect(`/sources/${state}`)
|
||||
}
|
||||
|
@ -2,7 +2,7 @@ import axios from "axios";
|
||||
import cuid from "cuid";
|
||||
import crypto from "crypto";
|
||||
import type { FastifyReply, FastifyRequest } from "fastify";
|
||||
import { encrypt, errorHandler, isDev, listSettings, prisma } from "../../../lib/common";
|
||||
import { encrypt, errorHandler, getAPIUrl, isDev, listSettings, prisma } from "../../../lib/common";
|
||||
import { checkContainer, removeContainer } from "../../../lib/docker";
|
||||
import { scheduler } from "../../../lib/scheduler";
|
||||
import { getApplicationFromDB, getApplicationFromDBWebhook } from "../../api/v1/applications/handlers";
|
||||
@ -16,7 +16,7 @@ export async function configureGitLabApp(request: FastifyRequest, reply: Fastify
|
||||
let domain = `http://${request.hostname}`;
|
||||
if (fqdn) domain = fqdn;
|
||||
if (isDev) {
|
||||
domain = `http://localhost:3001`;
|
||||
domain = getAPIUrl();
|
||||
}
|
||||
const params = new URLSearchParams({
|
||||
client_id: appId,
|
||||
@ -28,7 +28,7 @@ export async function configureGitLabApp(request: FastifyRequest, reply: Fastify
|
||||
});
|
||||
const { data } = await axios.post(`${htmlUrl}/oauth/token`, params)
|
||||
if (isDev) {
|
||||
return reply.redirect(`http://localhost:3000/webhooks/success?token=${data.access_token}`)
|
||||
return reply.redirect(`${getAPIUrl()}/webhooks/success?token=${data.access_token}`)
|
||||
}
|
||||
return reply.redirect(`/webhooks/success?token=${data.access_token}`)
|
||||
} catch ({ status, message, ...other }) {
|
||||
|
@ -1,14 +1,28 @@
|
||||
import { browser, dev } from '$app/env';
|
||||
import { dev } from '$app/env';
|
||||
import Cookies from 'js-cookie';
|
||||
|
||||
export function getAPIUrl() {
|
||||
if (GITPOD_WORKSPACE_URL) {
|
||||
const {href} = new URL(GITPOD_WORKSPACE_URL)
|
||||
const newURL = href.replace('https://','https://3001-').replace(/\/$/,'')
|
||||
const { href } = new URL(GITPOD_WORKSPACE_URL)
|
||||
const newURL = href.replace('https://', 'https://3001-').replace(/\/$/, '')
|
||||
return newURL
|
||||
}
|
||||
return dev ? 'http://localhost:3001' : 'http://localhost:3000';
|
||||
}
|
||||
export function getWebhookUrl(type: string) {
|
||||
console.log(GITPOD_WORKSPACE_URL)
|
||||
if (GITPOD_WORKSPACE_URL) {
|
||||
const { href } = new URL(GITPOD_WORKSPACE_URL)
|
||||
const newURL = href.replace('https://', 'https://3001-').replace(/\/$/, '')
|
||||
if (type === 'github') {
|
||||
return `${newURL}/webhooks/github/events`
|
||||
}
|
||||
if (type === 'gitlab') {
|
||||
return `${newURL}/webhooks/gitlab/events`
|
||||
}
|
||||
}
|
||||
return `https://webhook.site/0e5beb2c-4e9b-40e2-a89e-32295e570c21/events`;
|
||||
}
|
||||
async function send({
|
||||
method,
|
||||
path,
|
||||
|
@ -8,7 +8,7 @@
|
||||
import { onMount } from 'svelte';
|
||||
import { dev } from '$app/env';
|
||||
import { goto } from '$app/navigation';
|
||||
import { del, get, post } from '$lib/api';
|
||||
import { del, get, getAPIUrl, getWebhookUrl, post } from '$lib/api';
|
||||
import { t } from '$lib/translations';
|
||||
import { errorNotification } from '$lib/common';
|
||||
import { appSession } from '$lib/store';
|
||||
@ -18,7 +18,7 @@
|
||||
const from = $page.url.searchParams.get('from');
|
||||
|
||||
let url = settings?.fqdn ? settings.fqdn : window.location.origin;
|
||||
if (dev) url = `http://localhost:3001`;
|
||||
if (dev) url = getAPIUrl();
|
||||
|
||||
const updateDeployKeyIdUrl = `/applications/${id}/configuration/deploykey`;
|
||||
|
||||
@ -228,7 +228,7 @@
|
||||
}
|
||||
async function setWebhook(url: any, webhookToken: any) {
|
||||
const host = dev
|
||||
? 'https://webhook.site/0e5beb2c-4e9b-40e2-a89e-32295e570c21'
|
||||
? getWebhookUrl('gitlab')
|
||||
: `${window.location.origin}/webhooks/gitlab/events`;
|
||||
try {
|
||||
await post(
|
||||
|
@ -2,7 +2,7 @@
|
||||
export let source: any;
|
||||
export let settings: any;
|
||||
import { page } from '$app/stores';
|
||||
import { post } from '$lib/api';
|
||||
import { getAPIUrl, getWebhookUrl, post } from '$lib/api';
|
||||
import Explainer from '$lib/components/Explainer.svelte';
|
||||
import { toast } from '@zerodevx/svelte-toast';
|
||||
import { t } from '$lib/translations';
|
||||
@ -67,7 +67,7 @@
|
||||
const { organization, htmlUrl } = source;
|
||||
const { fqdn } = settings;
|
||||
const host = dev
|
||||
? 'http://localhost:3001'
|
||||
? getAPIUrl()
|
||||
: fqdn
|
||||
? fqdn
|
||||
: `http://${window.location.host}` || '';
|
||||
@ -81,7 +81,7 @@
|
||||
url: host,
|
||||
hook_attributes: {
|
||||
url: dev
|
||||
? 'https://webhook.site/0e5beb2c-4e9b-40e2-a89e-32295e570c21/events'
|
||||
? getWebhookUrl('github')
|
||||
: `${host}/webhooks/github/events`
|
||||
},
|
||||
redirect_url: `${host}/webhooks/github`,
|
||||
|
@ -4,7 +4,7 @@
|
||||
import Explainer from '$lib/components/Explainer.svelte';
|
||||
import { page } from '$app/stores';
|
||||
import { onMount } from 'svelte';
|
||||
import { post } from '$lib/api';
|
||||
import { getAPIUrl, post } from '$lib/api';
|
||||
import { dev } from '$app/env';
|
||||
import CopyPasswordField from '$lib/components/CopyPasswordField.svelte';
|
||||
import { toast } from '@zerodevx/svelte-toast';
|
||||
@ -17,7 +17,7 @@
|
||||
let url = settings.fqdn ? settings.fqdn : window.location.origin;
|
||||
|
||||
if (dev) {
|
||||
url = `http://localhost:3001`;
|
||||
url = getAPIUrl();
|
||||
}
|
||||
let loading = false;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user