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.

fix: dnt

Andras Bacsai3f078517a0ab
diff --git a/apps/api/src/index.ts b/apps/api/src/index.ts
index be4113d7c2..ac4fb9be10 100644
--- a/apps/api/src/index.ts
+++ b/apps/api/src/index.ts
@@ -9,7 +9,7 @@ import autoLoad from '@fastify/autoload';
import socketIO from 'fastify-socket.io'
import socketIOServer from './realtime'
-import { asyncExecShell, cleanupDockerStorage, createRemoteEngineConfiguration, decrypt, encrypt, executeDockerCmd, executeSSHCmd, generateDatabaseConfiguration, isDev, listSettings, prisma, startTraefikProxy, startTraefikTCPProxy, version } from './lib/common';
+import { asyncExecShell, cleanupDockerStorage, createRemoteEngineConfiguration, decrypt, executeDockerCmd, executeSSHCmd, generateDatabaseConfiguration, isDev, listSettings, prisma, sentryDSN, startTraefikProxy, startTraefikTCPProxy, version } from './lib/common';
import { scheduler } from './lib/scheduler';
import { compareVersions } from 'compare-versions';
import Graceful from '@ladjs/graceful'
@@ -36,7 +36,6 @@ declare module 'fastify' {
const port = isDev ? 3001 : 3000;
const host = '0.0.0.0';
-const sentryDSN = 'https://[email protected]/4504236622217216';
(async () => {
const settings = await prisma.setting.findFirst()
@@ -240,39 +239,36 @@ async function getTagsTemplates() {
}
async function initServer() {
const appId = process.env['COOLIFY_APP_ID'];
+ const settings = await prisma.setting.findUnique({ where: { id: '0' } })
try {
let doNotTrack = false
- if (appId === '') {
- doNotTrack = true
- }
+ if (appId === '') doNotTrack = true
+ doNotTrack = settings.doNotTrack
await prisma.setting.update({ where: { id: '0' }, data: { doNotTrack } })
} catch (error) {
console.log(error)
}
try {
- const settings = await prisma.setting.findUnique({ where: { id: '0' } })
- if (!settings.sentryDSN) {
- if (appId == '') {
- console.log('Telemetry disabled')
- return
- } else {
- await prisma.setting.update({ where: { id: '0' }, data: { sentryDSN } })
- }
+ if (settings.doNotTrack === true) {
+ console.log('[000] Telemetry disabled...')
+
} else {
if (settings.sentryDSN !== sentryDSN) {
await prisma.setting.update({ where: { id: '0' }, data: { sentryDSN } })
}
+ // Initialize Sentry
+ Sentry.init({
+ debug: true,
+ dsn: sentryDSN,
+ environment: isDev ? 'development' : 'production',
+ release: version
+ });
+ console.log('[000] Sentry initialized...')
}
- // Initialize Sentry
- Sentry.init({
- dsn: sentryDSN,
- environment: isDev ? 'development' : 'production',
- release: version
- });
+
} catch (error) {
console.error(error)
}
-
try {
console.log(`[001] Initializing server...`);
await asyncExecShell(`docker network create --attachable coolify`);
diff --git a/apps/api/src/lib/common.ts b/apps/api/src/lib/common.ts
index 11859366b1..80104ebbe0 100644
--- a/apps/api/src/lib/common.ts
+++ b/apps/api/src/lib/common.ts
@@ -8,6 +8,7 @@ import type { Config } from 'unique-names-generator';
import generator from 'generate-password';
import crypto from 'crypto';
import { promises as dns } from 'dns';
+import * as Sentry from '@sentry/node';
import { PrismaClient } from '@prisma/client';
import os from 'os';
import sshConfig from 'ssh-config';
@@ -19,7 +20,7 @@ import { scheduler } from './scheduler';
export const version = '3.12.0';
export const isDev = process.env.NODE_ENV === 'development';
-
+export const sentryDSN = 'https://[email protected]/4504236622217216';
const algorithm = 'aes-256-ctr';
const customConfig: Config = {
dictionaries: [adjectives, colors, animals],
@@ -1491,6 +1492,7 @@ export function errorHandler({
message: string | any;
}) {
if (message.message) message = message.message;
+ Sentry.captureException({ status, message });
throw { status, message };
}
export async function generateSshKeyPair(): Promise<{ publicKey: string; privateKey: string }> {
diff --git a/apps/api/src/routes/api/v1/settings/handlers.ts b/apps/api/src/routes/api/v1/settings/handlers.ts
index 49284210cf..b03eed9bb9 100644
--- a/apps/api/src/routes/api/v1/settings/handlers.ts
+++ b/apps/api/src/routes/api/v1/settings/handlers.ts
@@ -1,8 +1,8 @@
import { promises as dns } from 'dns';
import { X509Certificate } from 'node:crypto';
-
+import * as Sentry from '@sentry/node';
import type { FastifyReply, FastifyRequest } from 'fastify';
-import { asyncExecShell, checkDomainsIsValidInDNS, decrypt, encrypt, errorHandler, isDev, isDNSValid, isDomainConfigured, listSettings, prisma } from '../../../../lib/common';
+import { asyncExecShell, checkDomainsIsValidInDNS, decrypt, encrypt, errorHandler, isDev, isDNSValid, isDomainConfigured, listSettings, prisma, sentryDSN, version } from '../../../../lib/common';
import { AddDefaultRegistry, CheckDNS, CheckDomain, DeleteDomain, OnlyIdInBody, SaveSettings, SaveSSHKey, SetDefaultRegistry } from './types';
@@ -78,6 +78,15 @@ export async function saveSettings(request: FastifyRequest<SaveSettings>, reply:
if (minPort && maxPort) {
await prisma.setting.update({ where: { id }, data: { minPort, maxPort } });
}
+ if (doNotTrack === false) {
+ Sentry.init({
+ debug: true,
+ dsn: sentryDSN,
+ environment: isDev ? 'development' : 'production',
+ release: version
+ });
+ console.log('Sentry initialized')
+ }
return reply.code(201).send()
} catch ({ status, message }) {
return errorHandler({ status, message })
@@ -110,7 +119,7 @@ export async function checkDomain(request: FastifyRequest<CheckDomain>) {
if (fqdn) fqdn = fqdn.toLowerCase();
const found = await isDomainConfigured({ id, fqdn });
if (found) {
- throw "Domain already configured";
+ throw { message: "Domain already configured" };
}
if (isDNSCheckEnabled && !forceSave && !isDev) {
const hostname = request.hostname.split(':')[0]