Skip to content

Commit 80e0a6b

Browse files
committed
chore: improve nginx and env configuration
1 parent 69a8c20 commit 80e0a6b

File tree

10 files changed

+58
-3
lines changed

10 files changed

+58
-3
lines changed

.changeset/shy-wasps-press.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@quassel/frontend": patch
3+
---
4+
5+
Improve nginx and env configuration

apps/frontend/.docker/entrypoint.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/bin/sh
2+
set -xe
3+
4+
: "${API_URL?Define the api endpoint}"
5+
6+
sed -i "s/\/\/REPLACE_WITH_API_URL/$API_URL/g" /usr/share/nginx/html/index.html
7+
8+
exec "$@"

apps/frontend/.docker/nginx.conf

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
server {
2+
listen 80;
3+
4+
location / {
5+
root /usr/share/nginx/html;
6+
index index.html index.htm;
7+
8+
try_files $uri $uri/ /index.html =404;
9+
}
10+
}

apps/frontend/Dockerfile

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
11
FROM docker.io/nginx:stable-alpine
2+
23
COPY dist/ /usr/share/nginx/html/
4+
COPY ./.docker/nginx.conf /etc/nginx/conf.d/default.conf
5+
COPY ./.docker/entrypoint.sh /
6+
7+
RUN chmod +x /entrypoint.sh
8+
39
EXPOSE 80
10+
ENTRYPOINT ["/entrypoint.sh"]
411
CMD ["nginx", "-g", "daemon off;"]

apps/frontend/index.html

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@
2020
min-height: 100%;
2121
}
2222
</style>
23+
<script type="text/javascript">
24+
window.env = {
25+
apiUrl: '//REPLACE_WITH_API_URL'
26+
};
27+
</script>
2328
</head>
2429
<body>
2530
<div id="root"></div>

apps/frontend/src/configuration.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
function getEnv(key: keyof Exclude<typeof window.env, undefined>) {
2+
if (window.env === undefined) return;
3+
if (window.env[key]?.startsWith("//")) return;
4+
5+
return window.env[key];
6+
}
7+
8+
export const C = {
9+
env: {
10+
apiUrl: getEnv("apiUrl") || "http://localhost:3000",
11+
},
12+
};

apps/frontend/src/stores/api.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import createFetchClient from "openapi-fetch";
22
import createClient from "openapi-react-query";
33
import type { paths } from "../api.gen";
4+
import { C } from "../configuration";
45

56
const fetchClient = createFetchClient<paths>({
6-
baseUrl: "https://api.test.quassel.ch",
7+
baseUrl: C.env.apiUrl,
78
credentials: "include",
89
});
910
export const $api = createClient(fetchClient);

apps/frontend/src/types.d.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,11 @@ declare module "@tanstack/react-query" {
99
};
1010
}
1111
}
12+
13+
declare global {
14+
interface Window {
15+
env?: {
16+
apiUrl?: string;
17+
};
18+
}
19+
}

docs/examples/docker-compose.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ services:
6767
frontend:
6868
image: ghcr.io/openscript-ch/quassel-frontend:latest
6969
environment:
70-
API: api.test.example.com
70+
API_URL: https://api.test.example.com
7171
labels:
7272
- "com.centurylinklabs.watchtower.enable=true"
7373
- "traefik.enable=true"

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
{
22
"name": "quassel",
3-
"version": "0.0.0",
43
"private": true,
54
"description": "Quassel: Gather language exposure data ",
65
"scripts": {

0 commit comments

Comments
 (0)