-
Notifications
You must be signed in to change notification settings - Fork 58
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
Fixed broken local devserver due to env vars #2453
Fixed broken local devserver due to env vars #2453
Conversation
Signed-off-by: Alexander Schreiner <github@alexander-schreiner.de> Signed-off-by: Alexander Schreiner (ext.) <github@alexander-schreiner.de>
9f8ad7a
to
4c6af0f
Compare
Hey, nice work catching this and tracing it back to mistakes that me and @henrycatalinismith made in #2452. The misspelling of "ORGANIZE" is obviously just a typo that needs to be fixed, as you've done here. But the problem with the unserializable variables, might not be best solved by requiring them, but by handling their undefined state. This was done before #2452 by falling back to I'm not sure whether I prefer just falling back to What do you think @xela1601 and @henrycatalinismith? |
Ah cool! I had wondered what the point was with the type being My understanding of what I've read here in this thread is that what's problematic is when the My next question after understanding this is: why is it so necessary to include these empty values at all? Do we have functionality in some of the page components that depends on being able to enumerate all possible environment variables, whether blank or otherwise? If not, I think it seems a little strange to add a whole other kind of blank value to this union type just to allow ourselves to do something that serves no practical purpose. If that's the case, perhaps we could try something like this instead so that we exclude undefined environment variables from the return value of diff --git a/src/utils/next.ts b/src/utils/next.ts
index 7a57da808..9ef37aa39 100644
--- a/src/utils/next.ts
+++ b/src/utils/next.ts
@@ -205,7 +205,8 @@ export const scaffold =
if (hasProps(result)) {
result.props = {
...result.props,
- envVars: {
+ envVars: Object.fromEntries(
+ Object.entries({
FEAT_AREAS: process.env.FEAT_AREAS,
INSTANCE_OWNER_HREF: process.env.INSTANCE_OWNER_HREF,
INSTANCE_OWNER_NAME: process.env.INSTANCE_OWNER_NAME,
@@ -213,7 +214,8 @@ export const scaffold =
ZETKIN_APP_DOMAIN: process.env.ZETKIN_APP_DOMAIN,
ZETKIN_GEN2_ORGANIZE_URL: process.env.ZETKIN_GEN2_ORGANZE_URL,
ZETKIN_PRIVACY_POLICY_LINK: process.env.ZETKIN_PRIVACY_POLICY_LINK,
- },
+ }).filter(([_, value]) => value !== undefined)
+ ),
lang,
messages,
user: ctx.user, If this can possibly work I think it might be preferable on the basis that the intention and purpose are much more immediately clear from the code. It's clear in the above that we're filtering out undefined values and even without a helpful comment the reader can begin to guess at why that might be happening. By contrast, sneaking them through here as nulls and adding |
I don't think it's that weird to say that these config variables need to be either I don't find your solution @henrycatalinismith very readable (and I suspect it will cause typing errors because |
Been daydreaming about this all day, it's a fun little puzzle. Here's a whole other option. diff --git a/src/utils/next.ts b/src/utils/next.ts
index 7a57da808..d2259daa9 100644
--- a/src/utils/next.ts
+++ b/src/utils/next.ts
@@ -1,4 +1,5 @@
import { getIronSession } from 'iron-session';
+import { isUndefined, omitBy } from 'lodash';
import { ParsedUrlQuery } from 'querystring';
import {
GetServerSideProps,
@@ -205,7 +206,8 @@ export const scaffold =
if (hasProps(result)) {
result.props = {
...result.props,
- envVars: {
+ envVars: omitBy(
+ {
FEAT_AREAS: process.env.FEAT_AREAS,
INSTANCE_OWNER_HREF: process.env.INSTANCE_OWNER_HREF,
INSTANCE_OWNER_NAME: process.env.INSTANCE_OWNER_NAME,
@@ -214,6 +216,8 @@ export const scaffold =
ZETKIN_GEN2_ORGANIZE_URL: process.env.ZETKIN_GEN2_ORGANZE_URL,
ZETKIN_PRIVACY_POLICY_LINK: process.env.ZETKIN_PRIVACY_POLICY_LINK,
},
+ isUndefined // Undefined values are not JSON serializable
+ ),
lang, Possible to further refactor a utility function out of this like so. const omitUndefined = (obj) => _.omitBy(obj, _.isUndefined); |
I personally like the idea of the envVars: omitUndefined({
FEAT_AREAS: process.env.FEAT_AREAS,
INSTANCE_OWNER_HREF: process.env.INSTANCE_OWNER_HREF,
INSTANCE_OWNER_NAME: process.env.INSTANCE_OWNER_NAME,
ZETKIN_GEN2_ORGANIZE_URL: process.env.ZETKIN_GEN2_ORGANIZE_URL,
ZETKIN_PRIVACY_POLICY_LINK: process.env.ZETKIN_PRIVACY_POLICY_LINK,
}) |
Yeah, I like this solution! 💯 |
Shall I implement it this way? |
Please do! You can put it in |
to prevent local dev server from crashing Signed-off-by: Alexander Schreiner <github@alexander-schreiner.de>
4c6af0f
to
f73e015
Compare
done :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice work! I think this is where it needs to be now. I added a comment below just because I want to hear your take on it.
Will merge when I've heard back!
b2c15b0
to
a8acc4a
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Based on the answer from Alex's LLM (🤔) on my comment in the last review, I assumed I was right about the bundle size. I tried changing the imports via Github, which of course failed. So I made a change locally and force-pushed it.
With that, I think this is ready to merge!
Description
While i was looking for the reason, my local devserver is not working anymore, I realized there was a typo 🙈 and several env vars were undefined which causes the next-server to crash
Within
process.env.ZETKIN_GEN2_ORGANZE_URL
anI
was missing.This caused the following error when running
yarn devserver
and going tolocalhost:3000
:Also as the error logs say env var
FEAT_AREAS
is missing (alsoINSTANCE_OWNER_HREF
,INSTANCE_OWNER_NAME
andMUIX_LICENSE_KEY
).I resolved this by adding them as empty env vars to
.env.development
Screenshots
Changes
process.env.ZETKIN_GEN2_ORGANZE_URL
->process.env.ZETKIN_GEN2_ORGANIZE_URL
INSTANCE_OWNER_HREF
,INSTANCE_OWNER_NAME
andMUIX_LICENSE_KEY
as empty env vars to.env.development
Notes to reviewer
.env.test