Skip to content

📈 Open source, privacy-first web analytics — a cookie-less Google Analytics alternative with built-in error tracking and performance monitoring. Self-host it or use our cloud. Get started for free!

fix: app fails to start-up when isSelfhosted is set to true and email is absent

Blue Mousebb79744e8a46
diff --git a/src/common/constants.ts b/src/common/constants.ts
index b0b3fe337..e539332ac 100644
--- a/src/common/constants.ts
+++ b/src/common/constants.ts
@@ -1,9 +1,10 @@
import { ClickHouse } from 'clickhouse'
import Redis from 'ioredis'
import { hash } from 'blake3'
-import { v5 as uuidv5 } from 'uuid'
import * as _toNumber from 'lodash/toNumber'
+import { getSelfhostedUUID } from './utils'
+
require('dotenv').config()
const redis = new Redis(
@@ -148,9 +149,12 @@ initialiseClickhouse()
const SELFHOSTED_EMAIL = process.env.EMAIL
const SELFHOSTED_PASSWORD = process.env.PASSWORD
const UUIDV5_NAMESPACE = '912c64c1-73fd-42b6-859f-785f839a9f68'
+const DEFAULT_SELFHOSTED_UUID = 'deadbeef-dead-beef-dead-beefdeadbeef'
+
const SELFHOSTED_UUID = isSelfhosted
- ? uuidv5(SELFHOSTED_EMAIL, UUIDV5_NAMESPACE)
+ ? getSelfhostedUUID()
: ''
+
const TWO_FACTOR_AUTHENTICATION_APP_NAME =
process.env.TWO_FACTOR_AUTHENTICATION_APP_NAME
@@ -251,4 +255,5 @@ export {
CAPTCHA_SECRET_KEY_LENGTH,
PRODUCTION_ORIGIN,
isTgTokenPresent,
+ DEFAULT_SELFHOSTED_UUID,
}
diff --git a/src/common/utils.ts b/src/common/utils.ts
index 99afb0e92..a51b337ab 100644
--- a/src/common/utils.ts
+++ b/src/common/utils.ts
@@ -1,5 +1,6 @@
-import { ForbiddenException, NotFoundException, HttpException } from '@nestjs/common'
+import { NotFoundException, HttpException } from '@nestjs/common'
import { hash } from 'blake3'
+import { v5 as uuidv5 } from 'uuid'
import * as randomstring from 'randomstring'
import * as _sample from 'lodash/sample'
import * as _join from 'lodash/join'
@@ -14,8 +15,10 @@ import * as _round from 'lodash/round'
import * as dayjs from 'dayjs'
import * as utc from 'dayjs/plugin/utc'
import * as _map from 'lodash/map'
-import { redis } from './constants'
-import { clickhouse } from './constants'
+
+import {
+ clickhouse, redis, DEFAULT_SELFHOSTED_UUID, SELFHOSTED_EMAIL, UUIDV5_NAMESPACE,
+} from './constants'
import { Project } from '../project/entity/project.entity'
dayjs.extend(utc)
@@ -203,6 +206,14 @@ const millisecondsToSeconds = (milliseconds: number) => milliseconds / 1000
const generateRandomString = (length: number): string => randomstring.generate(length)
+const getSelfhostedUUID = (): string => {
+ try {
+ return uuidv5(SELFHOSTED_EMAIL, UUIDV5_NAMESPACE)
+ } catch {
+ return DEFAULT_SELFHOSTED_UUID
+ }
+}
+
export {
getRandomTip,
checkRateLimit,
@@ -216,4 +227,5 @@ export {
calculateRelativePercentage,
millisecondsToSeconds,
generateRandomString,
+ getSelfhostedUUID,
}