diff --git a/apps/api/prisma/migrations/20220817082342_custom_dns_servers/migration.sql b/apps/api/prisma/migrations/20220817082342_custom_dns_servers/migration.sql new file mode 100644 index 000000000..03588b549 --- /dev/null +++ b/apps/api/prisma/migrations/20220817082342_custom_dns_servers/migration.sql @@ -0,0 +1,2 @@ +-- AlterTable +ALTER TABLE "Setting" ADD COLUMN "DNSServers" TEXT; diff --git a/apps/api/prisma/schema.prisma b/apps/api/prisma/schema.prisma index f67424a53..695478cef 100644 --- a/apps/api/prisma/schema.prisma +++ b/apps/api/prisma/schema.prisma @@ -20,6 +20,7 @@ model Setting { proxyHash String? isAutoUpdateEnabled Boolean @default(false) isDNSCheckEnabled Boolean @default(true) + DNSServers String? isTraefikUsed Boolean @default(true) createdAt DateTime @default(now()) updatedAt DateTime @updatedAt diff --git a/apps/api/src/lib/common.ts b/apps/api/src/lib/common.ts index 75ad6ff86..96921d82a 100644 --- a/apps/api/src/lib/common.ts +++ b/apps/api/src/lib/common.ts @@ -307,6 +307,10 @@ export async function checkDoubleBranch(branch: string, projectId: number): Prom } export async function isDNSValid(hostname: any, domain: string): Promise { const { isIP } = await import('is-ip'); + const { DNSServers } = await listSettings(); + if (DNSServers) { + dns.setServers([DNSServers]); + } let resolves = []; try { if (isIP(hostname)) { @@ -320,7 +324,6 @@ export async function isDNSValid(hostname: any, domain: string): Promise { try { let ipDomainFound = false; - dns.setServers(['1.1.1.1', '8.8.8.8']); const dnsResolve = await dns.resolve4(domain); if (dnsResolve.length > 0) { for (const ip of dnsResolve) { @@ -412,7 +415,12 @@ export async function checkDomainsIsValidInDNS({ hostname, fqdn, dualCerts }): P const { isIP } = await import('is-ip'); const domain = getDomain(fqdn); const domainDualCert = domain.includes('www.') ? domain.replace('www.', '') : `www.${domain}`; - dns.setServers(['1.1.1.1', '8.8.8.8']); + + const { DNSServers } = await listSettings(); + if (DNSServers) { + dns.setServers([DNSServers]); + } + let resolves = []; try { if (isIP(hostname)) { @@ -1553,7 +1561,7 @@ export async function configureServiceType({ }); } else if (type === 'appwrite') { const opensslKeyV1 = encrypt(generatePassword()); - const executorSecret = encrypt(generatePassword()); + const executorSecret = encrypt(generatePassword()); const redisPassword = encrypt(generatePassword()); const mariadbHost = `${id}-mariadb` const mariadbUser = cuid(); diff --git a/apps/api/src/routes/api/v1/applications/handlers.ts b/apps/api/src/routes/api/v1/applications/handlers.ts index cea2ca294..ce03c6e7c 100644 --- a/apps/api/src/routes/api/v1/applications/handlers.ts +++ b/apps/api/src/routes/api/v1/applications/handlers.ts @@ -18,7 +18,7 @@ export async function listApplications(request: FastifyRequest) { const { teamId } = request.user const applications = await prisma.application.findMany({ where: { teams: { some: { id: teamId === '0' ? undefined : teamId } } }, - include: { teams: true, destinationDocker: true } + include: { teams: true, destinationDocker: true, settings: true } }); const settings = await prisma.setting.findFirst() return { diff --git a/apps/api/src/routes/api/v1/handlers.ts b/apps/api/src/routes/api/v1/handlers.ts index 6d3112e97..ae558320e 100644 --- a/apps/api/src/routes/api/v1/handlers.ts +++ b/apps/api/src/routes/api/v1/handlers.ts @@ -4,7 +4,7 @@ import axios from 'axios'; import compare from 'compare-versions'; import cuid from 'cuid'; import bcrypt from 'bcryptjs'; -import { asyncExecShell, asyncSleep, cleanupDockerStorage, errorHandler, isDev, prisma, uniqueName, version } from '../../../lib/common'; +import { asyncExecShell, asyncSleep, cleanupDockerStorage, errorHandler, isDev, listSettings, prisma, uniqueName, version } from '../../../lib/common'; import type { FastifyReply, FastifyRequest } from 'fastify'; import type { Login, Update } from '.'; @@ -97,7 +97,8 @@ export async function showDashboard(request: FastifyRequest) { const userId = request.user.userId; const teamId = request.user.teamId; const applications = await prisma.application.findMany({ - where: { teams: { some: { id: teamId === '0' ? undefined : teamId } } } + where: { teams: { some: { id: teamId === '0' ? undefined : teamId } } }, + include: { settings: true } }); const databases = await prisma.database.findMany({ where: { teams: { some: { id: teamId === '0' ? undefined : teamId } } } @@ -105,10 +106,12 @@ export async function showDashboard(request: FastifyRequest) { const services = await prisma.service.findMany({ where: { teams: { some: { id: teamId === '0' ? undefined : teamId } } } }); + const settings = await listSettings(); return { applications, databases, services, + settings, }; } catch ({ status, message }) { return errorHandler({ status, message }) diff --git a/apps/api/src/routes/api/v1/settings/handlers.ts b/apps/api/src/routes/api/v1/settings/handlers.ts index 073dbd7e3..068d2c97e 100644 --- a/apps/api/src/routes/api/v1/settings/handlers.ts +++ b/apps/api/src/routes/api/v1/settings/handlers.ts @@ -33,12 +33,13 @@ export async function saveSettings(request: FastifyRequest, reply: minPort, maxPort, isAutoUpdateEnabled, - isDNSCheckEnabled + isDNSCheckEnabled, + DNSServers } = request.body const { id } = await listSettings(); await prisma.setting.update({ where: { id }, - data: { isRegistrationEnabled, dualCerts, isAutoUpdateEnabled, isDNSCheckEnabled } + data: { isRegistrationEnabled, dualCerts, isAutoUpdateEnabled, isDNSCheckEnabled, DNSServers } }); if (fqdn) { await prisma.setting.update({ where: { id }, data: { fqdn } }); @@ -54,6 +55,10 @@ export async function saveSettings(request: FastifyRequest, reply: export async function deleteDomain(request: FastifyRequest, reply: FastifyReply) { try { const { fqdn } = request.body + const { DNSServers } = await listSettings(); + if (DNSServers) { + dns.setServers([DNSServers]); + } let ip; try { ip = await dns.resolve(fqdn); diff --git a/apps/api/src/routes/api/v1/settings/types.ts b/apps/api/src/routes/api/v1/settings/types.ts index a33b614a4..d8fcf816d 100644 --- a/apps/api/src/routes/api/v1/settings/types.ts +++ b/apps/api/src/routes/api/v1/settings/types.ts @@ -8,7 +8,8 @@ export interface SaveSettings { minPort: number, maxPort: number, isAutoUpdateEnabled: boolean, - isDNSCheckEnabled: boolean + isDNSCheckEnabled: boolean, + DNSServers: string } } export interface DeleteDomain { diff --git a/apps/ui/src/lib/store.ts b/apps/ui/src/lib/store.ts index 89e38b6b8..7c851b96a 100644 --- a/apps/ui/src/lib/store.ts +++ b/apps/ui/src/lib/store.ts @@ -1,3 +1,4 @@ +import { dev } from '$app/env'; import cuid from 'cuid'; import { writable, readable, type Writable } from 'svelte/store'; @@ -73,7 +74,7 @@ export const location: Writable = writable(null) export const setLocation = (resource: any, settings?: any) => { if (resource.settings.isBot && resource.exposePort) { disabledButton.set(false); - return location.set(`http://${settings.ipv4}:${resource.exposePort}`) + return location.set(`http://${dev ? 'localhost' : settings.ipv4}:${resource.exposePort}`) } if (GITPOD_WORKSPACE_URL && resource.exposePort) { const { href } = new URL(GITPOD_WORKSPACE_URL); diff --git a/apps/ui/src/routes/applications/[id]/__layout.svelte b/apps/ui/src/routes/applications/[id]/__layout.svelte index 85f8001d2..3ec7107b7 100644 --- a/apps/ui/src/routes/applications/[id]/__layout.svelte +++ b/apps/ui/src/routes/applications/[id]/__layout.svelte @@ -141,8 +141,8 @@ if ( application.gitSourceId && application.destinationDockerId && - application.fqdn && - !application.settings.isBot + (application.fqdn || + application.settings.isBot) ) { await getStatus(); statusInterval = setInterval(async () => { @@ -409,37 +409,39 @@ - - + + + + + + + + + {/if} -
- changeSettings('previews')} - title={$t('application.enable_mr_pr_previews')} - description={$t('application.enable_preview_deploy_mr_pr_requests')} - /> -
+ {#if !application.settings.isBot} +
+ changeSettings('previews')} + title={$t('application.enable_mr_pr_previews')} + description={$t('application.enable_preview_deploy_mr_pr_requests')} + /> +
+ {/if}
Destination Missing
- {:else if !application.fqdn} + {:else if !application.fqdn && !application.settings.isBot}
URL Missing
diff --git a/apps/ui/src/routes/index.svelte b/apps/ui/src/routes/index.svelte index f28009843..63ae5fa47 100644 --- a/apps/ui/src/routes/index.svelte +++ b/apps/ui/src/routes/index.svelte @@ -20,35 +20,38 @@