Skip to content

Use next-runtime-env for dynamic envs #515

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions packages/app/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@

# Sentry
next.config.original.js

public/__ENV.js
5 changes: 3 additions & 2 deletions packages/app/next.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
const { configureRuntimeEnv } = require('next-runtime-env/build/configure');
const { version } = require('./package.json');

configureRuntimeEnv();

const withNextra = require('nextra')({
theme: 'nextra-theme-docs',
themeConfig: './src/nextra.config.tsx',
Expand All @@ -23,8 +26,6 @@ module.exports = withNextra({
swcMinify: false,
publicRuntimeConfig: {
version,
hdxLocalDefaultConnections: process.env.HDX_LOCAL_DEFAULT_CONNECTIONS,
hdxLocalDefaultSources: process.env.HDX_LOCAL_DEFAULT_SOURCES,
},
productionBrowserSourceMaps: false,
...(process.env.NEXT_OUTPUT_STANDALONE === 'true'
Expand Down
1 change: 1 addition & 0 deletions packages/app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
"lodash": "^4.17.21",
"next": "13",
"next-query-params": "^4.1.0",
"next-runtime-env": "1",
"next-seo": "^4.28.1",
"nextra": "2.0.1",
"nextra-theme-docs": "^2.0.2",
Expand Down
15 changes: 15 additions & 0 deletions packages/app/pages/_document.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { Head, Html, Main, NextScript } from 'next/document';

export default function Document() {
return (
<Html lang="en">
<Head>
<script src="/__ENV.js" />
</Head>
<body>
<Main />
<NextScript />
</body>
</Html>
);
}
2 changes: 0 additions & 2 deletions packages/app/pages/benchmark.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import BenchmarkPage from '@/BenchmarkPage';

export default BenchmarkPage;

export { getServerSideProps } from '@/emptyGetServerSideProps';
2 changes: 0 additions & 2 deletions packages/app/pages/chart.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import ChartPage from '@/DBChartPage';

export default ChartPage;

export { getServerSideProps } from '@/emptyGetServerSideProps';
2 changes: 0 additions & 2 deletions packages/app/pages/dashboards/[dashboardId].tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import DashboardPage from '@/DBDashboardPage';

export { getServerSideProps } from '@/emptyGetServerSideProps';

export default DashboardPage;
2 changes: 0 additions & 2 deletions packages/app/pages/dashboards/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,2 @@
import DBDashboardPage from '@/DBDashboardPage';
export default DBDashboardPage;

export { getServerSideProps } from '@/emptyGetServerSideProps';
2 changes: 0 additions & 2 deletions packages/app/pages/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,2 @@
import LandingPage from '@/LandingPage';
export default LandingPage;

export { getServerSideProps } from '@/emptyGetServerSideProps';
2 changes: 0 additions & 2 deletions packages/app/pages/join-team.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import JoinTeamPage from '@/JoinTeamPage';

export default JoinTeamPage;

export { getServerSideProps } from '@/emptyGetServerSideProps';
2 changes: 0 additions & 2 deletions packages/app/pages/login/index.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import AuthPage from '@/AuthPage';

export { getServerSideProps } from '@/emptyGetServerSideProps';

export default function Login() {
return (
<div>
Expand Down
2 changes: 0 additions & 2 deletions packages/app/pages/register.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,3 @@ export default function Register() {
</div>
);
}

export { getServerSideProps } from '@/emptyGetServerSideProps';
2 changes: 0 additions & 2 deletions packages/app/pages/search/[savedSearchId].tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import SearchPage from '@/DBSearchPage';

export default SearchPage;

export { getServerSideProps } from '@/emptyGetServerSideProps';
2 changes: 0 additions & 2 deletions packages/app/pages/search/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import SearchPage from '@/DBSearchPage';

export default SearchPage;

export { getServerSideProps } from '@/emptyGetServerSideProps';
2 changes: 0 additions & 2 deletions packages/app/pages/services.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,2 @@
import ServicesDashboardPage from '@/ServicesDashboardPage';
export default ServicesDashboardPage;

export { getServerSideProps } from '@/emptyGetServerSideProps';
2 changes: 0 additions & 2 deletions packages/app/pages/team/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,2 @@
import TeamPage from '@/TeamPage';
export default TeamPage;

export { getServerSideProps } from '@/emptyGetServerSideProps';
16 changes: 8 additions & 8 deletions packages/app/src/config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import getConfig from 'next/config';

const { serverRuntimeConfig, publicRuntimeConfig } = getConfig();
import { env } from 'next-runtime-env';

export const SERVER_URL =
process.env.NEXT_PUBLIC_SERVER_URL ?? 'http://localhost:8000'; // NEXT_PUBLIC_SERVER_URL can be empty string
Expand All @@ -10,11 +8,13 @@ export const CLICKHOUSE_HOST =
process.env.NEXT_PUBLIC_CLICKHOUSE_HOST ?? `${SERVER_URL}/clickhouse-proxy`;

// ONLY USED IN LOCAL MODE
// ex: HDX_LOCAL_DEFAULT_CONNECTIONS='[{"id":"local","name":"Demo","host":"https://demo-ch.hyperdx.io","username":"demo","password":"demo"}]' HDX_LOCAL_DEFAULT_SOURCES='[{"id":"l701179602","kind":"trace","name":"Demo Traces","connection":"local","from":{"databaseName":"default","tableName":"otel_traces"},"timestampValueExpression":"Timestamp","defaultTableSelectExpression":"Timestamp, ServiceName, StatusCode, round(Duration / 1e6), SpanName","serviceNameExpression":"ServiceName","eventAttributesExpression":"SpanAttributes","resourceAttributesExpression":"ResourceAttributes","traceIdExpression":"TraceId","spanIdExpression":"SpanId","implicitColumnExpression":"SpanName","durationExpression":"Duration","durationPrecision":9,"parentSpanIdExpression":"ParentSpanId","spanKindExpression":"SpanKind","spanNameExpression":"SpanName","logSourceId":"l-758211293","statusCodeExpression":"StatusCode","statusMessageExpression":"StatusMessage"},{"id":"l-758211293","kind":"log","name":"Demo Logs","connection":"local","from":{"databaseName":"default","tableName":"otel_logs"},"timestampValueExpression":"TimestampTime","defaultTableSelectExpression":"Timestamp, ServiceName, SeverityText, Body","serviceNameExpression":"ServiceName","severityTextExpression":"SeverityText","eventAttributesExpression":"LogAttributes","resourceAttributesExpression":"ResourceAttributes","traceIdExpression":"TraceId","spanIdExpression":"SpanId","implicitColumnExpression":"Body","traceSourceId":"l701179602"}]' yarn dev:local
export const HDX_LOCAL_DEFAULT_CONNECTIONS =
publicRuntimeConfig.hdxLocalDefaultConnections;
export const HDX_LOCAL_DEFAULT_SOURCES =
publicRuntimeConfig.hdxLocalDefaultSources;
// ex: NEXT_PUBLIC_HDX_LOCAL_DEFAULT_CONNECTIONS='[{"id":"local","name":"Demo","host":"https://demo-ch.hyperdx.io","username":"demo","password":"demo"}]' NEXT_PUBLIC_HDX_LOCAL_DEFAULT_SOURCES='[{"id":"l701179602","kind":"trace","name":"Demo Traces","connection":"local","from":{"databaseName":"default","tableName":"otel_traces"},"timestampValueExpression":"Timestamp","defaultTableSelectExpression":"Timestamp, ServiceName, StatusCode, round(Duration / 1e6), SpanName","serviceNameExpression":"ServiceName","eventAttributesExpression":"SpanAttributes","resourceAttributesExpression":"ResourceAttributes","traceIdExpression":"TraceId","spanIdExpression":"SpanId","implicitColumnExpression":"SpanName","durationExpression":"Duration","durationPrecision":9,"parentSpanIdExpression":"ParentSpanId","spanKindExpression":"SpanKind","spanNameExpression":"SpanName","logSourceId":"l-758211293","statusCodeExpression":"StatusCode","statusMessageExpression":"StatusMessage"},{"id":"l-758211293","kind":"log","name":"Demo Logs","connection":"local","from":{"databaseName":"default","tableName":"otel_logs"},"timestampValueExpression":"TimestampTime","defaultTableSelectExpression":"Timestamp, ServiceName, SeverityText, Body","serviceNameExpression":"ServiceName","severityTextExpression":"SeverityText","eventAttributesExpression":"LogAttributes","resourceAttributesExpression":"ResourceAttributes","traceIdExpression":"TraceId","spanIdExpression":"SpanId","implicitColumnExpression":"Body","traceSourceId":"l701179602"}]' yarn dev:local
export const HDX_LOCAL_DEFAULT_CONNECTIONS = env(
'NEXT_PUBLIC_HDX_LOCAL_DEFAULT_CONNECTIONS',
);
export const HDX_LOCAL_DEFAULT_SOURCES = env(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel it would be handy if the NEXT_PUBLIC_IS_LOCAL_MODE is also runtime

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll leave that to a separate PR, since I think we do different images/serving modes for that anyways.

'NEXT_PUBLIC_HDX_LOCAL_DEFAULT_SOURCES',
);

export const HDX_API_KEY = process.env.HYPERDX_API_KEY as string; // for nextjs server
export const HDX_SERVICE_NAME =
Expand Down
7 changes: 0 additions & 7 deletions packages/app/src/emptyGetServerSideProps.tsx

This file was deleted.

10 changes: 10 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4166,6 +4166,7 @@ __metadata:
msw-storybook-addon: "npm:^2.0.2"
next: "npm:13"
next-query-params: "npm:^4.1.0"
next-runtime-env: "npm:1"
next-seo: "npm:^4.28.1"
nextra: "npm:2.0.1"
nextra-theme-docs: "npm:^2.0.2"
Expand Down Expand Up @@ -20698,6 +20699,15 @@ __metadata:
languageName: node
linkType: hard

"next-runtime-env@npm:1":
version: 1.7.4
resolution: "next-runtime-env@npm:1.7.4"
dependencies:
chalk: "npm:^4.1.2"
checksum: 10c0/fc169fd4c77cf610fe4e82a170638023a836f3e406efc62735bd9db5b8d63ba5a797037285d6608a9814375643c95ce97b8272f71911c7d7cd29e5b977350c79
languageName: node
linkType: hard

"next-seo@npm:^4.28.1":
version: 4.29.0
resolution: "next-seo@npm:4.29.0"
Expand Down