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

Fix issue #124 wrong servers when installed #127

Conversation

gianmarcotoso
Copy link
Contributor

@gianmarcotoso gianmarcotoso commented Jul 1, 2023

Fixes Issue #124

Defines the CUSTOM_LEMMY_SERVERS as a variable through vite.config.ts, allowing it to be present after PWA installation.

This requires reading the the environment via Vite's loadEnv function, and define the config using a function in order to be able to read the current mode (development, production, test).

The CUSTOM_LEMMY_SERVERS can be defined in the environment either system wide or through a .env file such as .env.production.local or .env.development.local (the .local is not strictly needed, but .local files are gitignored).

Sidenote: I added a .prettierrc because I use different settings and they were wreaking havoc on the code, this way it should be consistent.

Gian Marco Toso added 3 commits July 1, 2023 16:28
the CUSTOM_LEMMY_SERVER env variable is now
injected as a variable defined in vite.config.ts,
allowing it to persist even after the PWA has
been installed
@aeharding
Copy link
Owner

Looks great!

@aeharding aeharding merged commit 8bde519 into aeharding:main Jul 1, 2023
aeharding added a commit that referenced this pull request Jul 1, 2023
@aeharding
Copy link
Owner

aeharding commented Jul 1, 2023

Hi @gianmarcotoso

I forgot to test this in production.

Essentially, post build-time, you should be able to configure custom servers

If I do:

  • yarn build
  • NODE_ENV=production CUSTOM_LEMMY_SERVERS=lemmy.ml PORT=5106 node server.mjs

The lemmy.ml server is not being picked up.

So I am reverting for now. Feel free to make another PR.

aeharding added a commit that referenced this pull request Jul 1, 2023
@gianmarcotoso
Copy link
Contributor Author

Hey @aeharding

I see your point, I admit I worked under the (wrong) assumption that they should be configured at compile time. I'll look for another way, as the PWA is misbehaving anyway after installation, but yes, for now it's best to revert.

@aeharding
Copy link
Owner

Thanks @gianmarcotoso!

@gianmarcotoso
Copy link
Contributor Author

@aeharding I'm thinking that there is no good solution using env in this case, as it does not carry over when installing the PWA. I was thinking about adding the ability for the user add and remove custom servers at runtime, saving them in localstorage. Would this approach be ok with you? Where should this happen, in the servers screen or in the settings screen?

Or maybe it could suffice saving the value of CUSTOM_LEMMY_SERVERS in localstorage, since the login info carries over after installing?

@aeharding
Copy link
Owner

aeharding commented Jul 1, 2023

The custom lemmy servers should not be user configurable.

Maybe there is a something we can hook into on vite-pwa to move over custom servers?

Otherwise, we could make an express route in server.mjs to respond with servers (with aggressive 1 day caching) via xhr. But that's async, so would be a bit more work.

@gianmarcotoso
Copy link
Contributor Author

Hm, I see.

So, I've tried using localStorage to save the content of window.CUSTOM_LEMMY_SERVERS when it's available and it does work in production, so that might be a quick and viable way to solve this.

Can I ask, why shouldn't the servers be configurable (on a per-user basis) if the app lives entirely on the user's device? I'm very likely missing a piece of the puzzle here :)

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