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.

feat: ipv4 and ipv6

Andras Bacsai9e3ba295ea03
diff --git a/apps/api/prisma/migrations/20220722203927_ipaddress/migration.sql b/apps/api/prisma/migrations/20220722203927_ipaddress/migration.sql
new file mode 100644
index 0000000000..21d45ada32
--- /dev/null
+++ b/apps/api/prisma/migrations/20220722203927_ipaddress/migration.sql
@@ -0,0 +1,3 @@
+-- AlterTable
+ALTER TABLE "Setting" ADD COLUMN "ipv4" TEXT;
+ALTER TABLE "Setting" ADD COLUMN "ipv6" TEXT;
diff --git a/apps/api/prisma/schema.prisma b/apps/api/prisma/schema.prisma
index 72c926f3f1..37f306b70b 100644
--- a/apps/api/prisma/schema.prisma
+++ b/apps/api/prisma/schema.prisma
@@ -11,6 +11,8 @@ datasource db {
model Setting {
id String @id @default(cuid())
fqdn String? @unique
+ ipv4 String?
+ ipv6 String?
isRegistrationEnabled Boolean @default(false)
dualCerts Boolean @default(false)
minPort Int @default(9000)
diff --git a/apps/api/src/index.ts b/apps/api/src/index.ts
index e302df635e..6a96660270 100644
--- a/apps/api/src/index.ts
+++ b/apps/api/src/index.ts
@@ -5,7 +5,7 @@ import env from '@fastify/env';
import cookie from '@fastify/cookie';
import path, { join } from 'path';
import autoLoad from '@fastify/autoload';
-import { asyncExecShell, isDev, prisma } from './lib/common';
+import { asyncExecShell, isDev, listSettings, prisma } from './lib/common';
import { scheduler } from './lib/scheduler';
declare module 'fastify' {
@@ -101,10 +101,10 @@ fastify.listen({ port, host }, async (err: any, address: any) => {
process.exit(1);
}
console.log(`Coolify's API is listening on ${host}:${port}`);
- await initServer()
+ await initServer();
await scheduler.start('deployApplication');
await scheduler.start('cleanupStorage');
- await scheduler.start('checkProxies')
+ await scheduler.start('checkProxies');
// Check if no build is running
@@ -130,8 +130,24 @@ fastify.listen({ port, host }, async (err: any, address: any) => {
if (!scheduler.workers.has('deployApplication')) await scheduler.start('deployApplication');
}
});
+ await getIPAddress();
});
+async function getIPAddress() {
+ const { publicIpv4, publicIpv6 } = await import('public-ip')
+ try {
+ const settings = await listSettings();
+ if (!settings.ipv4) {
+ const ipv4 = await publicIpv4({ timeout: 2000 })
+ await prisma.setting.update({ where: { id: settings.id }, data: { ipv4 } })
+ }
+
+ if (!settings.ipv6) {
+ const ipv6 = await publicIpv6({ timeout: 2000 })
+ await prisma.setting.update({ where: { id: settings.id }, data: { ipv6 } })
+ }
+ } catch (error) { }
+}
async function initServer() {
try {
await asyncExecShell(`docker network create --attachable coolify`);
diff --git a/apps/api/src/routes/api/v1/base/index.ts b/apps/api/src/routes/api/v1/base/index.ts
index 9eaa8c40a4..76735a0322 100644
--- a/apps/api/src/routes/api/v1/base/index.ts
+++ b/apps/api/src/routes/api/v1/base/index.ts
@@ -1,10 +1,13 @@
import { FastifyPluginAsync } from 'fastify';
-import { errorHandler, version } from '../../../../lib/common';
+import { errorHandler, listSettings, version } from '../../../../lib/common';
const root: FastifyPluginAsync = async (fastify): Promise<void> => {
fastify.get('/', async () => {
+ const settings = await listSettings()
try {
return {
+ ipv4: settings.ipv4,
+ ipv6: settings.ipv6,
version,
whiteLabeled: process.env.COOLIFY_WHITE_LABELED === 'true',
whiteLabeledIcon: process.env.COOLIFY_WHITE_LABELED_ICON,
diff --git a/apps/ui/src/lib/store.ts b/apps/ui/src/lib/store.ts
index 096be2e526..8b7a8d8304 100644
--- a/apps/ui/src/lib/store.ts
+++ b/apps/ui/src/lib/store.ts
@@ -1,6 +1,8 @@
import { writable, readable, type Writable, type Readable } from 'svelte/store';
interface AppSession {
+ ipv4: string | null,
+ ipv6: string | null,
version: string | null,
userId: string | null,
teamId: string | null,
@@ -17,6 +19,8 @@ interface AppSession {
}
export const loginEmail: Writable<string | undefined> = writable()
export const appSession: Writable<AppSession> = writable({
+ ipv4: null,
+ ipv6: null,
version: null,
userId: null,
teamId: null,
diff --git a/apps/ui/src/routes/__layout.svelte b/apps/ui/src/routes/__layout.svelte
index a6932eae08..d25437d2cc 100644
--- a/apps/ui/src/routes/__layout.svelte
+++ b/apps/ui/src/routes/__layout.svelte
@@ -65,6 +65,8 @@
<script lang="ts">
export let baseSettings: any;
+ $appSession.ipv4 = baseSettings.ipv4;
+ $appSession.ipv6 = baseSettings.ipv6;
$appSession.version = baseSettings.version;
$appSession.whiteLabeled = baseSettings.whiteLabeled;
$appSession.whiteLabeledDetails.icon = baseSettings.whiteLabeledIcon;
diff --git a/apps/ui/src/routes/databases/[id]/_Databases/_Databases.svelte b/apps/ui/src/routes/databases/[id]/_Databases/_Databases.svelte
index 94c8ed75e1..461185742c 100644
--- a/apps/ui/src/routes/databases/[id]/_Databases/_Databases.svelte
+++ b/apps/ui/src/routes/databases/[id]/_Databases/_Databases.svelte
@@ -51,7 +51,7 @@
return `${database.type}://${
databaseDbUser ? databaseDbUser + ':' : ''
}${databaseDbUserPassword}@${
- isPublic ? (settings.fqdn ? getDomain(settings.fqdn) : window.location.hostname) : database.id
+ isPublic ? ($appSession.ipv4) : database.id
}:${isPublic ? database.publicPort : privatePort}/${databaseDefault}`;
}