-
Notifications
You must be signed in to change notification settings - Fork 189
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
Fixes #1576, Added FRONTEND env variable, updated routes/index.js #1606
Conversation
env.example
Outdated
# 'gatsby' - The Gatsby Front-End | ||
# 'next' - The NextJs Front-End | ||
# Our default value for FRONTEND is 'gatsby' | ||
FRONTEND='gatsby' |
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.
Remove the surrounding quotes, all values are strings:
FRONTEND=gatsby
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.
Will do, thanks!
netlify.toml
Outdated
@@ -8,3 +8,4 @@ | |||
API_URL="https://dev.telescope.cdot.systems" | |||
# We need to expose the API_URL to the front-end too | |||
NEXT_PUBLIC_API_URL="https://dev.telescope.cdot.systems" | |||
FRONTEND='gatsby' |
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.
Should be next
on Netlify.
src/backend/web/routes/index.js
Outdated
@@ -17,7 +17,7 @@ const user = require('./user'); | |||
const query = require('./query'); | |||
|
|||
const router = express.Router(); | |||
|
|||
const { FRONTEND } = process.env.FRONTEND; |
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.
In the rest of this code, we seem to be doing process.env.FRONTEND
inline, instead of pulling things out. Can you match that below?
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.
Careful here: using destructuring, you have to remove the name of the variable in the rhs.
const { FRONTEND } = process.env;
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.
Will do! Everything should be fixed along with the rest of your suggestions
} else if (FRONTEND === 'next') { | ||
router.use(express.static(path.join(__dirname, '../../../frontend/next/out'))); | ||
} else { | ||
throw new Error( |
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.
Let's test that this does what we want (e.g., we should probably crash right now).
src/backend/web/routes/index.js
Outdated
// Or serve the static files in the Gatsby build directory | ||
} else if (FRONTEND === 'gatsby') { |
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.
Let's make sure that case doesn't affect these (e.g., .toLowerCase()
on the frontend values we compare against).
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.
Looks good. @Metropass, please update the team tomorrow about this change so people can update their local .env, since it will throw right now if it's missing.
Question related to that: should we default to Gatsby if it's missing instead of throwing? That is:
- gatsby: use gatsby
- next: use next
- {not set}: use gatsby
- anything else: throw
@@ -17,7 +17,6 @@ const user = require('./user'); | |||
const query = require('./query'); | |||
|
|||
const router = express.Router(); | |||
|
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.
Watch out for spurious whitespace changes like this, as it churns git history unnecessarily.
I say for now, we should have it default to gatsby since the next transition is not complete yet. Whenever that's complete, unless we have any sort of reason to keep gatsby, we can just have it serve next, and throw if anything else other than that is used |
src/backend/web/routes/index.js
Outdated
@@ -45,13 +45,13 @@ if (process.env.NODE_ENV === 'development') { | |||
// Allow proxying the Gatsby dev server through our backend if PROXY_FRONTEND=1 is set in env | |||
router.use('/', createProxyMiddleware({ target: 'http://localhost:8000', changeOrigin: true })); | |||
// Or serve the static files in the Gatsby build directory | |||
} else if (process.env.FRONTEND.toLowerCase() === 'gatsby') { | |||
} else if (process.env.FRONTEND.toLowerCase() === 'gatsby' || process.env.FRONTEND === '') { |
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.
Question: will process.env.FRONTEND.toLowerCase()
break if FRONTEND
isn't defined? That is, should this be:
else if(!process.env.FRONTEND || process.env.FRONTEND === '' || process.env.FRONTEND.toLowerCase() === 'gatsby') {...}
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.
Oh, that's a good point, I'll make that change real quick
is this ready for review? |
@manekenpix Should be ready now! |
@Metropass This might be a stupid question but how can I test this? Also does this mean I have to copy a new example |
@@ -4,6 +4,16 @@ NODE_ENV=development | |||
# PORT is the port used by the web server | |||
PORT=3000 |
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.
Does this change affect this line?
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.
It does, thanks for bring it up.
It seems like I need to make a conditional statement within the package.json
@humphd cc'ing just for clarity, Are we allowed to make conditionals in our packages for Telescope?
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.
I don't think they're related. PORT=3000
is for telescope (telescope serving the back end), The change @chrispinkney is talking about (this) is for next's production server (a separate server to serve the production build, but telescope has nothing to do with it).
It's not a stupid question at all!
It's not a stupid question at all! |
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.
Otherwise LGTM!
Start redis and elasticsearch in docker:
npm run build
npm run build:next
set FRONTEND=gatsby
npm start
set FRONTEND=next
npm start
Hope this is right 😄. Everything started up and ran
@@ -4,6 +4,16 @@ NODE_ENV=development | |||
# PORT is the port used by the web server | |||
PORT=3000 | |||
|
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.
Haha sorry, I know it's pedantic, but can you get rid of the extra newlines on line 6 and 15?
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.
This PR looks okay. We're switching to next and not gatsby so we can make this exclusively next instead. You'll need to rebase and fix conflicts here too.
Read #1733 for context
Hm good point. In fact AFAIK we'll be removing Gatsby entirely when Next finally lands. Not sure! Something to think about I guess @Metropass |
This was started nearly a month ago, and we needed it then, but at this point, I don't think it's useful, since we're moving to a single front-end. Closing. |
Issue This PR Addresses
Closes #1576
Created a
FRONTEND
variable for all of the .env files, and added a conditional if withinbackend/routes/index.js
Currently, the only two values that can be accepted for
FRONTEND
are:gatsby
andnext
gatsby
is the default value as of this Pull RequestType of Change
Description
Checklist