Skip to content

Commit b47ecdc

Browse files
authored
feat: Frontend app title environment variable (danny-avila#291)
* Add app name change support * fix indentation
1 parent e4f639b commit b47ecdc

File tree

6 files changed

+75
-57
lines changed

6 files changed

+75
-57
lines changed

client/.env.example

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
###########################
2+
# App configuration:
3+
###########################
4+
5+
# Custom app name, this text will be displayed in the landing page and the footer.
6+
VITE_APP_TITLE="ChatGPT Clone"
7+
18
###########################
29
# Server URL configuration:
310
###########################

client/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<head>
44
<meta charset="utf-8" />
55
<meta name="theme-color" content="#343541">
6-
<title>ChatGPT Clone</title>
6+
<title>%VITE_APP_TITLE%</title>
77
<link
88
rel="shortcut icon"
99
href="#"

client/src/components/Input/Footer.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export default function Footer() {
99
rel="noreferrer"
1010
className="underline"
1111
>
12-
ChatGPT Clone
12+
{import.meta.env.VITE_APP_TITLE || "ChatGPT Clone"}
1313
</a>
1414
. Serves and searches all conversations reliably. All AI convos under one house. Pay per call and not
1515
per month (cents compared to dollars).

client/src/components/ui/Landing.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ export default function Landing() {
3333
<div className="flex h-full flex-col items-center overflow-y-auto pt-0 text-sm dark:bg-gray-800">
3434
<div className="w-full px-6 text-gray-800 dark:text-gray-100 md:flex md:max-w-2xl md:flex-col lg:max-w-3xl">
3535
<h1 id="landing-title" className="mt-6 ml-auto mr-auto mb-10 flex items-center justify-center gap-2 text-center text-4xl font-semibold sm:mb-16 md:mt-[10vh]">
36-
ChatGPT Clone
36+
{import.meta.env.VITE_APP_TITLE || "ChatGPT Clone"}
3737
</h1>
3838
<div className="items-start gap-3.5 text-center md:flex">
3939
<div className="mb-8 flex flex-1 flex-col gap-3.5 md:mb-auto">

client/vite.config.ts

Lines changed: 61 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,66 +1,76 @@
1-
import { defineConfig } from 'vite';
1+
import { defineConfig, loadEnv } from 'vite';
22
import react from '@vitejs/plugin-react';
33
import path from 'path';
44
import type { Plugin } from "vite";
55

66
// https://vitejs.dev/config/
77
export default defineConfig({
8-
server: {
9-
host: 'localhost',
10-
port: 3090,
11-
strictPort: false,
12-
proxy: {
13-
'/api': {
14-
target: 'http://localhost:3080',
15-
changeOrigin: true
16-
},
17-
'/auth': {
18-
target: 'http://localhost:3080',
19-
changeOrigin: true
20-
},
21-
'/oauth': {
22-
target: 'http://localhost:3080',
23-
changeOrigin: true
24-
}
25-
}
26-
},
27-
plugins: [react(), sourcemapExclude({excludeNodeModules: true})],
28-
publicDir: './public',
29-
build: {
30-
sourcemap: true,
31-
outDir: './dist',
32-
rollupOptions: {
33-
output: {
34-
manualChunks: id => {
35-
if (id.includes('node_modules')) {
36-
return 'vendor';
37-
}
8+
server: {
9+
host: 'localhost',
10+
port: 3090,
11+
strictPort: false,
12+
proxy: {
13+
'/api': {
14+
target: 'http://localhost:3080',
15+
changeOrigin: true
16+
},
17+
'/auth': {
18+
target: 'http://localhost:3080',
19+
changeOrigin: true
20+
},
21+
'/oauth': {
22+
target: 'http://localhost:3080',
23+
changeOrigin: true
24+
}
25+
}
26+
},
27+
plugins: [react(), sourcemapExclude({ excludeNodeModules: true })],
28+
publicDir: './public',
29+
build: {
30+
sourcemap: true,
31+
outDir: './dist',
32+
rollupOptions: {
33+
output: {
34+
manualChunks: id => {
35+
if (id.includes('node_modules')) {
36+
return 'vendor';
37+
}
38+
}
39+
}
40+
}
41+
},
42+
resolve: {
43+
alias: {
44+
'~': path.join(__dirname, 'src/')
3845
}
39-
}
40-
}
41-
},
42-
resolve: {
43-
alias: {
44-
'~': path.join(__dirname, 'src/')
4546
}
46-
}
4747
});
4848

4949
interface SourcemapExclude {
50-
excludeNodeModules?: boolean;
50+
excludeNodeModules?: boolean;
5151
}
5252
export function sourcemapExclude(opts?: SourcemapExclude): Plugin {
53-
return {
54-
name: "sourcemap-exclude",
55-
transform(code: string, id: string) {
56-
if (opts?.excludeNodeModules && id.includes("node_modules")) {
57-
return {
58-
code,
59-
// https://github.com/rollup/rollup/blob/master/docs/plugin-development/index.md#source-code-transformations
60-
map: { mappings: "" },
61-
};
62-
}
63-
},
64-
};
53+
return {
54+
name: "sourcemap-exclude",
55+
transform(code: string, id: string) {
56+
if (opts?.excludeNodeModules && id.includes("node_modules")) {
57+
return {
58+
code,
59+
// https://github.com/rollup/rollup/blob/master/docs/plugin-development/index.md#source-code-transformations
60+
map: { mappings: "" },
61+
};
62+
}
63+
},
64+
};
6565
}
6666

67+
function htmlPlugin(env: ReturnType<typeof loadEnv>) {
68+
return {
69+
name: "html-transform",
70+
transformIndexHtml: {
71+
enforce: "pre" as const,
72+
transform: (html: string): string =>
73+
html.replace(/%(.*?)%/g, (match, p1) => env[p1] ?? match),
74+
},
75+
};
76+
}

e2e/specs/landing.spec.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
import {expect, test} from '@playwright/test';
1+
import { expect, test } from '@playwright/test';
22

3-
test('landing page', async ({page}) => {
3+
4+
test('landing page', async ({ page }) => {
45
await page.goto('http://localhost:3080/');
56
// expect (await page.title()).toBe('ChatGPT Clone');
6-
expect (await page.textContent('#landing-title')).toBe('ChatGPT Clone');
7+
expect(await page.textContent('#landing-title')).toBe(import.meta.env.VITE_APP_TITLE || "ChatGPT Clone");
78
});

0 commit comments

Comments
 (0)