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

Use Gatsby dev to proxy dev-server #280

Merged
merged 6 commits into from
Mar 10, 2021
Merged

Use Gatsby dev to proxy dev-server #280

merged 6 commits into from
Mar 10, 2021

Conversation

jameshadfield
Copy link
Member

@jameshadfield jameshadfield commented Mar 4, 2021

Closes #158. From #158 (comment):

So, my approach is similar to option 1, which is running both the dev-server and gatsby dev server, but I take advantage of Gatsby's built-in development API proxy (https://www.gatsbyjs.com/docs/api-proxy/).

I made a proof-of-concept in my fork https://github.com/didithilmy/nextstrain.org/tree/use-gatsby-dev. Try to run npm run dev from the root directory.

Unfortunately, it involves Gatsby knowing what paths are NOT supposed to be served by Gatsby, which is located in server.js, outside static-site. In my solution, I moved the auspicePaths into a separate file, which is included by static-site/gatsby-config.js.

Signed-off-by: James Hadfield <hadfield.james@gmail.com>
@tsibley tsibley temporarily deployed to nextstrain-s-use-gatsby-xmxirl March 4, 2021 00:58 Inactive
Copy link
Member Author

@jameshadfield jameshadfield left a comment

Choose a reason for hiding this comment

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

Thanks @didithilmy -- this solution looks good and should become the go-to method for development inside this repo. I don't have any issues with moving the paths into a separate file. Tested in both dev & production modes and couldn't find any issues.

@eharkins would you mind taking a look 🙏

@jameshadfield jameshadfield temporarily deployed to nextstrain-s-use-gatsby-xmxirl March 4, 2021 01:12 Inactive
@jameshadfield
Copy link
Member Author

jameshadfield commented Mar 4, 2021

We should also update the README through this PR

@eharkins eharkins temporarily deployed to nextstrain-s-use-gatsby-xmxirl March 6, 2021 01:18 Inactive
Copy link
Contributor

@eharkins eharkins left a comment

Choose a reason for hiding this comment

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

I added some updates to the README and static-site/README @jameshadfield. npm run dev worked for me in my existing checkout of the repo.

However, when I created a fresh clone to try and come up with instructions for the README for running a dev server from scratch, I got inconsistent errors when building the site from scratch, so couldn't come up with a complete set of instructions for running a dev server from scatch. Maybe you or @didithilmy can come up with a complete set of instructions for needs to happen before you can run a dev server if you are starting anew and add them here:
https://github.com/nextstrain/nextstrain.org/pull/280/files#diff-b335630551682c19a781afebcf4d07bf978fb1f8ac04c6bf87428ed5106870f5R39
?

@didithilmy
Copy link
Contributor

Can you try running npm run build first?
I don’t think I can push commits to this PR, since the branch isn’t on my fork.

@jameshadfield
Copy link
Member Author

jameshadfield commented Mar 7, 2021

However, when I created a fresh clone to try and come up with instructions for the README for running a dev server from scratch, I got inconsistent errors when building the site from scratch

Good find -- thanks for running this extra check. I think this occurs because npm ci hasn't yet been run from within the static-site directory. Recommending npm run build is smart as that'll both install static-site deps and also build auspice.

@eharkins
Copy link
Contributor

eharkins commented Mar 8, 2021

I still get

  TypeError: createProxyMiddleware is not a function
  - gatsby-config.js:79 forEach.path
     /Users/eharkins/nextstrain/test/nextstrain.org/static-site/gatsby-config.js:79:9

after running the following in a new clone of this branch:

npm ci
npm run build
npm run dev

which seems like it should work since it completes the build of the static site (along with installing dependencies) during npm run build without error (the error comes when i run npm run dev). But if this doesn't happen for either of you then probably an issue on my end.

Commit f5f67bc added `http-proxy-middleware` as an explicit dependency, rather than a transitive dependency. This had the side-effect of upgrading the package from v0 to v1, the latter of which no longer exposes the `createProxyMiddleware` function as default, thus we need to use an explicit require to import it.

Co-authored-by: Muhammad Aditya Hilmy <didithilmy@gmail.com>
@jameshadfield jameshadfield temporarily deployed to nextstrain-s-use-gatsby-xmxirl March 9, 2021 23:18 Inactive
@jameshadfield
Copy link
Member Author

@eharkins this should now be working 🤞 could you re-test please?

@eharkins eharkins temporarily deployed to nextstrain-s-use-gatsby-xmxirl March 10, 2021 01:10 Inactive
@eharkins eharkins temporarily deployed to nextstrain-s-use-gatsby-xmxirl March 10, 2021 01:14 Inactive
Copy link
Contributor

@eharkins eharkins left a comment

Choose a reason for hiding this comment

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

Works now, thanks both!

I updated the README and static-site/README to make it explicit that running npm run build is necessary in both ways of running the server. Feel free to edit my language there.

@jameshadfield jameshadfield merged commit e77a4b4 into master Mar 10, 2021
@jameshadfield jameshadfield deleted the use-gatsby-dev branch March 10, 2021 02:04
eharkins added a commit that referenced this pull request Mar 12, 2021
this removes an old workaround made
obsolete by #280 and updates a comment
post- #271
jameshadfield pushed a commit that referenced this pull request Apr 10, 2021
this removes an old workaround made
obsolete by #280 and updates a comment
post- #271
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.

Allow gatsby dev server to use auspice server
4 participants