Skip to content

Commit 5e22c8b

Browse files
authored
Merge pull request #355 from shapehq/bugfix/avoiding-inline-environment-variable-values
Removes environment variables prefixed with NEXT_PUBLIC_
2 parents 5fc307a + 0bb70db commit 5e22c8b

File tree

13 files changed

+36
-43
lines changed

13 files changed

+36
-43
lines changed

.env.example

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
FRAMNA_DOCS_BASE_URL=http://localhost:3000
2+
FRAMNA_DOCS_TITLE=Framna Docs
3+
FRAMNA_DOCS_DESCRIPTION=Documentation for Framna's APIs
4+
FRAMNA_DOCS_HELP_URL=https://github.com/shapehq/framna-docs/wiki
25
FRAMNA_DOCS_PROJECT_CONFIGURATION_FILENAME=.shape-docs.yml
3-
NEXT_PUBLIC_FRAMNA_DOCS_TITLE=Framna Docs
4-
NEXT_PUBLIC_FRAMNA_DOCS_DESCRIPTION=Documentation for Framna's APIs
5-
NEXT_PUBLIC_FRAMNA_DOCS_HELP_URL=https://github.com/shapehq/framna-docs/wiki
66
NEXTAUTH_URL_INTERNAL=http://localhost:3000
77
NEXTAUTH_SECRET=use [openssl rand -base64 32] to generate a 32 bytes value
88
REDIS_URL=localhost

__test__/projects/updateWindowTitle.test.ts

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,9 @@
11
import { updateWindowTitle } from "@/features/projects/domain"
22

3-
test("It uses default title when there is no selection", async () => {
4-
const store: { title: string } = { title: "" }
5-
updateWindowTitle({
6-
storage: store,
7-
defaultTitle: "Demo Docs"
8-
})
9-
expect(store.title).toEqual("Demo Docs")
10-
})
11-
123
test("It leaves out specification when the specification has a generic name", async () => {
134
const store: { title: string } = { title: "" }
145
updateWindowTitle({
156
storage: store,
16-
defaultTitle: "Demo Docs",
177
project: {
188
id: "foo",
199
name: "foo",
@@ -49,7 +39,6 @@ test("It leaves out version when it is the defualt version", async () => {
4939
const store: { title: string } = { title: "" }
5040
updateWindowTitle({
5141
storage: store,
52-
defaultTitle: "Demo Docs",
5342
project: {
5443
id: "foo",
5544
name: "foo",
@@ -81,7 +70,6 @@ test("It adds version when it is not the defualt version", async () => {
8170
const store: { title: string } = { title: "" }
8271
updateWindowTitle({
8372
storage: store,
84-
defaultTitle: "Demo Docs",
8573
project: {
8674
id: "foo",
8775
name: "foo",

src/app/(authed)/(home)/(welcome)/page.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { Box, Typography } from "@mui/material"
22
import { grey } from "@mui/material/colors"
33
import { env } from "@/common"
44

5-
const SITE_NAME = env.getOrThrow("NEXT_PUBLIC_FRAMNA_DOCS_TITLE")
5+
const SITE_NAME = env.getOrThrow("FRAMNA_DOCS_TITLE")
66

77
const Page = () => {
88
return (

src/app/(authed)/(home)/[...slug]/page.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,17 @@ export default function Page() {
1212
useEffect(() => {
1313
navigateToSelectionIfNeeded()
1414
}, [project, version, specification, navigateToSelectionIfNeeded])
15-
// Update the window title to match selected project.
16-
const siteName = process.env.NEXT_PUBLIC_FRAMNA_DOCS_TITLE || ""
1715
useEffect(() => {
16+
if (!project) {
17+
return
18+
}
1819
updateWindowTitle({
1920
storage: document,
20-
defaultTitle: siteName,
2121
project,
2222
version,
2323
specification
2424
})
25-
}, [siteName, project, version, specification])
25+
}, [project, version, specification])
2626
return (
2727
<>
2828
{project && version && specification &&

src/app/(authed)/(home)/new/page.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import NewProjectSteps from "@/features/new-project/view/NewProjectSteps"
33
import { env, splitOwnerAndRepository } from "@/common"
44
import MessageLinkFooter from "@/common/ui/MessageLinkFooter"
55

6-
const HELP_URL = env.get("NEXT_PUBLIC_FRAMNA_DOCS_HELP_URL")
6+
const HELP_URL = env.get("FRAMNA_DOCS_HELP_URL")
77

88
const Page = () => {
99
const repositoryNameSuffix = env.getOrThrow("REPOSITORY_NAME_SUFFIX")

src/app/auth/signin/page.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ import { faGithub } from "@fortawesome/free-brands-svg-icons"
77
import SignInTexts from "@/features/auth/view/SignInTexts"
88
import MessageLinkFooter from "@/common/ui/MessageLinkFooter"
99

10-
const SITE_NAME = env.getOrThrow("NEXT_PUBLIC_FRAMNA_DOCS_TITLE")
11-
const HELP_URL = env.get("NEXT_PUBLIC_FRAMNA_DOCS_HELP_URL")
10+
const SITE_NAME = env.getOrThrow("FRAMNA_DOCS_TITLE")
11+
const HELP_URL = env.get("FRAMNA_DOCS_HELP_URL")
1212

1313
export default async function SignInPage() {
1414
return (

src/app/layout.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ import { env } from "@/common"
99
fontAwesomeConfig.autoAddCss = false
1010

1111
export const metadata: Metadata = {
12-
title: env.getOrThrow("NEXT_PUBLIC_FRAMNA_DOCS_TITLE"),
13-
description: env.getOrThrow("NEXT_PUBLIC_FRAMNA_DOCS_DESCRIPTION")
12+
title: env.getOrThrow("FRAMNA_DOCS_TITLE"),
13+
description: env.getOrThrow("FRAMNA_DOCS_DESCRIPTION")
1414
}
1515

1616
export default function RootLayout({ children }: { children: React.ReactNode }) {

src/composition.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ export const gitHubHookHandler = new GitHubHookHandler({
194194
}),
195195
eventHandler: new PostCommentPullRequestEventHandler({
196196
pullRequestCommenter: new PullRequestCommenter({
197-
siteName: env.getOrThrow("NEXT_PUBLIC_FRAMNA_DOCS_TITLE"),
197+
siteName: env.getOrThrow("FRAMNA_DOCS_TITLE"),
198198
domain: env.getOrThrow("FRAMNA_DOCS_BASE_URL"),
199199
repositoryNameSuffix: env.getOrThrow("REPOSITORY_NAME_SUFFIX"),
200200
projectConfigurationFilename: env.getOrThrow("FRAMNA_DOCS_PROJECT_CONFIGURATION_FILENAME"),

src/features/projects/domain/updateWindowTitle.ts

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,18 @@ import OpenApiSpecification from "./OpenApiSpecification"
44

55
export default function updateWindowTitle({
66
storage,
7-
defaultTitle,
87
project,
98
version,
109
specification,
1110
}: {
1211
storage: { title: string },
13-
defaultTitle: string,
14-
project?: Project,
12+
project: Project,
1513
version?: Version,
1614
specification?: OpenApiSpecification
1715
}) {
18-
if (!project || !version || !specification) {
19-
storage.title = defaultTitle
20-
return
21-
}
22-
if (!isSpecificationNameGeneric(specification.name)) {
16+
if (version && specification && !isSpecificationNameGeneric(specification.name)) {
2317
storage.title = `${project.displayName} / ${version.name} / ${specification.name}`
24-
} else if (!version.isDefault) {
18+
} else if (version && !version.isDefault) {
2519
storage.title = `${project.displayName} / ${version.name}`
2620
} else {
2721
storage.title = project.displayName

src/features/sidebar/view/SplitView.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@ import ClientSplitView from "./internal/ClientSplitView"
22
import { projectDataSource } from "@/composition"
33
import BaseSidebar from "./internal/sidebar/Sidebar"
44
import ProjectList from "./internal/sidebar/projects/ProjectList"
5+
import { env } from "@/common"
6+
7+
const SITE_NAME = env.getOrThrow("FRAMNA_DOCS_TITLE")
8+
const HELP_URL = env.get("FRAMNA_DOCS_HELP_URL")
59

610
const SplitView = ({ children }: { children?: React.ReactNode }) => {
711
return (
@@ -15,7 +19,8 @@ export default SplitView
1519

1620
const Sidebar = () => {
1721
return (
18-
<BaseSidebar>
22+
// The site name and help URL are passed as a properties to ensure the environment variables are read server-side.
23+
<BaseSidebar siteName={SITE_NAME} helpURL={HELP_URL}>
1924
<ProjectList projectDataSource={projectDataSource} />
2025
</BaseSidebar>
2126
)

0 commit comments

Comments
 (0)