Skip to content
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

chore: remove unnecessary env vars #3049

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

johncowen
Copy link
Contributor

Back in the mists of time we used a plugin in order to interpolate variables into our index.html file. We need this as in 'production' kuma itself uses our index.html as a template and interpolates variables into it.

Since then vite was upgraded to v5 which included functionality to interpolate variables, but only shell environment variables. This led us to drop the plugin for variable interpolation and use environment variables instead. The only thing is this meant we also started adding single line stringified JSON into environment variables.

This has always sat a little strange to me, these variables don't need to be shell environment variables and the stringified JSON is awkward.

Additionally lately we've realised we want to use a variable from the package.json file ("version": ...) to prevent duplication of this value in several places. (see #2967)

Because of this last point, I decided it was a good time to revisit this.


This PR aims to replicate exactly what the kuma binary does. We use JS to search and replace the golang style {{.BaseGuiPath}} variables with the actual variables. This is achieved using a relatively simple almost single line "inline vite plugin". As we replicate what kuma does, it means we don't have to do anything special anymore for 'production', we just ship the template as is, then only in 'development' we interpolate variables.

This also removes the need for the shell environment variables and the awkward stringified single-line JSON, and means we can reference the package.json#version via JS where we need to.

Lastly, I removed some fallback JSON that we had for a case that I don't think I've ever seen happen (an un-parseable HTML file), and really, if the HTML is un-parsable we probably don't want anyone using the resulting GUI as its likely to be very broken and/or unadvisable to use.

Overall this PR simplifies things quite a bit.

@johncowen johncowen self-assigned this Oct 9, 2024
@johncowen johncowen added this to the 2.10.x milestone Oct 9, 2024
Copy link

netlify bot commented Oct 9, 2024

Deploy Preview for kuma-gui ready!

Name Link
🔨 Latest commit 08daa9e
🔍 Latest deploy log https://app.netlify.com/sites/kuma-gui/deploys/6706a3fef1611400076054bc
😎 Deploy Preview https://deploy-preview-3049--kuma-gui.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@johncowen johncowen marked this pull request as ready for review October 9, 2024 15:47
@johncowen johncowen requested a review from a team as a code owner October 9, 2024 15:47
Copy link
Contributor

@slonka slonka left a comment

Choose a reason for hiding this comment

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

2 Qs

import { defineConfig, mergeConfig, type UserConfigFn, type UserConfig } from 'vite'

import { config as prodConfig } from './vite.config.production'
const version = JSON.parse(read('./package.json').toString()).version
// https://vitejs.dev/config/
export const config: UserConfigFn = (env) => {
return mergeConfig(
prodConfig(env),
Copy link
Contributor

Choose a reason for hiding this comment

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

unrelated, but why is there a prodConfig in a file called development.ts?

Comment on lines +20 to +27
baseGuiPath: '/gui',
apiUrl: 'http://localhost:5681',
version,
product: 'Kuma',
mode: 'global',
environment: 'universal',
storeType: 'postgres',
apiReadOnly: false,
Copy link
Contributor

Choose a reason for hiding this comment

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants