Skip to content

Commit

Permalink
Merge pull request #105 from akaene/main
Browse files Browse the repository at this point in the history
[#88] Migrate from Webpack to Vite
  • Loading branch information
blcham authored Mar 2, 2024
2 parents 09e9600 + 159ace9 commit 18b4948
Show file tree
Hide file tree
Showing 19 changed files with 1,315 additions and 7,297 deletions.
10 changes: 10 additions & 0 deletions .env.development
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
RECORD_MANAGER_API_URL=http://localhost:1235/record-manager/services/record-manager-server
RECORD_MANAGER_APP_TITLE=Record Manager
RECORD_MANAGER_APP_INFO=
RECORD_MANAGER_LANGUAGE=cs
RECORD_MANAGER_NAVIGATOR_LANGUAGE=true
RECORD_MANAGER_BASENAME=/
RECORD_MANAGER_EXTENSIONS=supplier
RECORD_MANAGER_AUTHENTICATION=internal
RECORD_MANAGER_AUTH_SERVER_URL=
RECORD_MANAGER_AUTH_CLIENT_ID=record-manager-ui
10 changes: 10 additions & 0 deletions .env.production
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
RECORD_MANAGER_API_URL=http://localhost:1235/record-manager/services/record-manager-server
RECORD_MANAGER_APP_TITLE=Record Manager
RECORD_MANAGER_APP_INFO=
RECORD_MANAGER_LANGUAGE=cs
RECORD_MANAGER_NAVIGATOR_LANGUAGE=true
RECORD_MANAGER_BASENAME=/
RECORD_MANAGER_EXTENSIONS=supplier
RECORD_MANAGER_AUTHENTICATION=internal
RECORD_MANAGER_AUTH_SERVER_URL=
RECORD_MANAGER_AUTH_CLIENT_ID=record-manager-ui
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
*.iml
node_modules
build
dist
coverage
junit.xml
.DS_store
Expand Down
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ ENV BASENAME=""
ENV APP_INFO='<a href="https://github.com/blcham" target="_blank" rel="noopener noreferrer" title="github.com/blcham, 2023">©&nbsp;github.com/blcham, 2023</a>'

# Copy the react build from Build Stage
COPY --from=build /usr/src/app/build /var/www
COPY --from=build /usr/src/app/dist /var/www

# Copy error page
COPY .docker/error.html /usr/share/nginx/html
Expand All @@ -42,7 +42,7 @@ COPY .docker/nginx.conf /etc/nginx/nginx.conf
COPY .docker/config.js.template /etc/nginx/config.js.template

# Copy our custom html template
COPY --from=build /usr/src/app/build/index.html /etc/nginx/index.html.template
COPY --from=build /usr/src/app/dist/index.html /etc/nginx/index.html.template

# from the outside.
EXPOSE 80
Expand Down
34 changes: 20 additions & 14 deletions config/index.js
Original file line number Diff line number Diff line change
@@ -1,31 +1,37 @@
/**
* Aggregated object of process.env and window.__config__ to allow dynamic configuration
*/

const viteEnvPrefix = "RECORD_MANAGER_";
const ENV = {
...Object.keys(process.env).reduce((acc, key) => {
const strippedKey = key.replace("RECORD_MANAGER_", "");
acc[strippedKey] = process.env[key];
return acc;
}, {}),
...(window).__config__,
...Object.keys(import.meta.env).reduce((acc, key) => {
if (key.startsWith(viteEnvPrefix)) {
const strippedKey = key.replace(viteEnvPrefix, "");
acc[strippedKey] = import.meta.env[key];
}
return acc;
}, {}),
...window.__config__,
};

/**
* Helper to make sure that all envs are defined properly
* @param name env variable name
* @param defaultValue Default variable name
*/
export const getEnv = (name, defaultValue) => {
const value = ENV[name] || defaultValue;
if (value !== undefined) {
return value;
}
throw new Error(`Missing environment variable: ${name}`);
const value = ENV[name] || defaultValue;
if (value !== undefined) {
return value;
}
throw new Error(`Missing environment variable: ${name}`);
};

export const API_URL = getEnv("API_URL");
export const APP_TITLE = getEnv("APP_TITLE", "Record Manager");
export const LANGUAGE = getEnv("LANGUAGE", "en");
export const NAVIGATOR_LANGUAGE = JSON.parse(getEnv("NAVIGATOR_LANGUAGE", "true"));
export const NAVIGATOR_LANGUAGE = JSON.parse(
getEnv("NAVIGATOR_LANGUAGE", "true")
);
export const BASENAME = getEnv("BASENAME", "");
export const EXTENSIONS = getEnv("EXTENSIONS", "");
export const EXTENSIONS = getEnv("EXTENSIONS", "");
export const APP_INFO = getEnv("APP_INFO", "© KBSS at FEE CTU in Prague, 2024");
2 changes: 1 addition & 1 deletion deploy/internal-auth/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ version: '3.9'

# Provide access to record-manager-ui that runs locally in dev mode
x-access-for-local-development: &local-dev-env
cors.allowedOrigins: "http://localhost:3000"
cors.allowedOrigins: "http://localhost:4173,http://localhost:5173"

services:
nginx:
Expand Down
16 changes: 16 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8" />
<link rel="icon" href="favicon.ico" />
<meta
name="viewport"
content="width=device-width, initial-scale=1, user-scalable=0"
/>
<script src="config.js"></script>
</head>
<body>
<div id="root"></div>
<script type="module" src="src/index.jsx"></script>
</body>
</html>
Loading

0 comments on commit 18b4948

Please sign in to comment.