Skip to content

Commit

Permalink
🚑 Added posthog when managed disto
Browse files Browse the repository at this point in the history
  • Loading branch information
naelob committed Dec 16, 2023
1 parent 0c58666 commit c660059
Show file tree
Hide file tree
Showing 8 changed files with 49 additions and 11 deletions.
5 changes: 4 additions & 1 deletion apps/webapp/.env.example
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
VITE_BACKEND_DOMAIN=https://api-staging.panora.dev #https://api-staging.panora.dev/
VITE_FRONTEND_DOMAIN=http://127.0.0.1:5173
VITE_FRONTEND_DOMAIN=http://127.0.0.1:5173
VITE_POSTHOG_KEY=<ph_project_api_key>
VITE_POSTHOG_HOST=<ph_instance_address>
VITE_DISTRIBUTION="managed" #managed or self-host
1 change: 1 addition & 0 deletions apps/webapp/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
"cmdk": "^0.2.0",
"date-fns": "^2.30.0",
"lucide-react": "^0.293.0",
"posthog-js": "^1.96.1",
"react": "^18.2.0",
"react-day-picker": "^8.9.1",
"react-dom": "^18.2.0",
Expand Down
14 changes: 13 additions & 1 deletion apps/webapp/src/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,21 @@ import React from 'react'
import ReactDOM from 'react-dom/client'
import App from './App.tsx'
import './index.css'
import { PostHogProvider} from 'posthog-js/react'
import config from './utils/config.ts'

const options = {
api_host: config.POSTHOG_HOST,
}

ReactDOM.createRoot(document.getElementById('root')!).render(
<React.StrictMode>
<App />
{config.DISTRIBUTION === "managed" ? <PostHogProvider
apiKey={config.POSTHOG_KEY}
options={options}
>
<App />
</PostHogProvider> : <App />
}
</React.StrictMode>,
)
3 changes: 3 additions & 0 deletions apps/webapp/src/utils/config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
const config = {
API_URL: import.meta.env.VITE_BACKEND_DOMAIN,
FRONT_DOMAIN: import.meta.env.VITE_FRONTEND_DOMAIN,
POSTHOG_HOST: import.meta.env.VITE_POSTHOG_HOST,
POSTHOG_KEY: import.meta.env.VITE_POSTHOG_KEY,
DISTRIBUTION: import.meta.env.VITE_DISTRIBUTION
};

export default config;
Expand Down
2 changes: 1 addition & 1 deletion packages/api/.env.example
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
ENV=dev
DISTRIBUTION=managed # could be self-host if you want to run it locally
DISTRIBUTION=managed # could be "self-host" if you want to run it locally
DATABASE_URL=
JWT_SECRET="SECRET"

Expand Down
1 change: 1 addition & 0 deletions packages/api/src/@core/utils/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const config = {
NODE_ENV: process.env.ENV,
DISTRIBUTION: process.env.DISTRIBUTION,
ENCRYPT_CRYPTO_SECRET_KEY: process.env.ENCRYPT_CRYPTO_SECRET_KEY,
REDIS_HOST: process.env.REDIS_HOST,
};

export default config;
21 changes: 13 additions & 8 deletions packages/api/src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { APP_INTERCEPTOR } from '@nestjs/core';
import { LoggerService } from '@@core/logger/logger.service';
import { CoreModule } from '@@core/core.module';
import { BullModule } from '@nestjs/bull';
import config from '@@core/utils/config';

@Module({
imports: [
Expand All @@ -27,13 +28,17 @@ import { BullModule } from '@nestjs/bull';
FileStorageModule,
CrmModule,
ConfigModule.forRoot({ isGlobal: true }),
SentryModule.forRoot({
dsn: process.env.SENTRY_DSN,
debug: true,
environment: 'dev',
release: 'some_release',
logLevels: ['debug'],
}),
...(config.DISTRIBUTION === 'managed'
? [
SentryModule.forRoot({
dsn: config.SENTRY_DSN,
debug: true,
environment: 'dev',
release: 'some_release',
logLevels: ['debug'],
}),
]
: []),
ScheduleModule.forRoot(),
LoggerModule.forRoot({
pinoHttp: {
Expand All @@ -50,7 +55,7 @@ import { BullModule } from '@nestjs/bull';
}),
BullModule.forRoot({
redis: {
host: process.env.REDIS_HOST,
host: config.REDIS_HOST,
port: 6379,
},
}),
Expand Down
13 changes: 13 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit c660059

Please sign in to comment.