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

Enable Gatsby functions in preview deploys #4919

Merged
merged 4 commits into from
Mar 8, 2022

Conversation

pettinarip
Copy link
Member

@pettinarip pettinarip commented Dec 29, 2021

Description

Currently we have the Netlify functions working in the Netlify context/server. On the other hand, in our preview deploys context (Gatsby Cloud) they are not working. We need to integrate them. This PR addresses this issue.

  • Added api folder to enable functions in gatsby cloud.
  • New env var GATSBY_FUNCTIONS_PATH to determine the path of the functions in each environment.
    • In Netlify: /.netlify/functions
    • In GC: /api

HOW TO TEST IT:

  1. Enter https://www.gatsbyjs.com/dashboard and use the site: pettinarip-ethereum-org-website-dev
  2. Change GATSBY_FUNCTIONS_PATH env var to /api => wait the build to finish => test the preview deploy
  3. Change GATSBY_FUNCTIONS_PATH env var to /.netlify/functions => wait the build to finish => test the netlify deploy (netlify url https://pettinarip-eth-org.netlify.app)
  4. In our prod deploy we will have 2 sites, one for our preview deploys and another for the prod ones

PROD IMPLEMENTATION:

  • ethereum-org-website-master: GATSBY_FUNCTIONS_PATH=/.netlify/functions
  • ethereum-org-website-dev: GATSBY_FUNCTIONS_PATH=/api

@gatsby-cloud
Copy link

gatsby-cloud bot commented Dec 29, 2021

Gatsby Cloud Build Report

ethereum-org-website-dev

🎉 Your build was successful! See the Deploy preview here.

Build Details

View the build logs here.

🕐 Build time: 6m

Performance

Lighthouse report

Metric Score
Performance 🔶 25
Accessibility 💚 97
Best Practices 💚 93
SEO 🔶 85

🔗 View full report

@pettinarip
Copy link
Member Author

pettinarip commented Dec 29, 2021

@minimalsm
Copy link
Contributor

@pettinarip the URL you've provided to test is re-directing to Gatsby cloud dashboard

On the deploy preview, the StatsBox is working 🎉🎉 The Roadmap isn't for me :( (returns a 500)

@@ -0,0 +1,8 @@
import { handler as lambda } from "../lambda/etherscan"
Copy link
Member

Choose a reason for hiding this comment

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

Glad to see we can re-use the code 😄

@wackerow
Copy link
Member

@samajammin It may be the cache functionality... it doesn't refetch every time you reload...
New private browser:
image
Then after refresh:
image

Also...
Getting the same on the contributing/translation-program pages, Status 500 but then the message shows

{"msg":"Request failed with status code 404"}

And on the about pages, status 500 and...

{"msg": "Request failed with status code 401"}

@pettinarip
Copy link
Member Author

Hey sorry about that @samajammin and @wackerow. I forgot to add some env vars in my netlify account. Now everything should be working.

Thought I'm not seeing the API requests in browser network tab

@samajammin you might need to test what Paul said. I see them in my browser 🤔

Copy link
Member

@samajammin samajammin left a comment

Choose a reason for hiding this comment

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

Looks close!

Everything I tested on https://pettinarip-eth-org.netlify.app/ appears to be working 👍

The roadmap endpoint on https://ethereumorgwebsitedev01-pettinaripethereumorgwebsitefu.gtsb.io/en/about isn't working for me:
Image 2022-02-01 at 5 40 23 PM

Any idea why the 500 error? This response from the endpoint is:

{"msg":"Request failed with status code 401"}

@samajammin
Copy link
Member

@pettinarip the translations endpoint on https://ethereumorgwebsitedev01-pettinaripethereumorgwebsitefu.gtsb.io/en/contributing/translation-program/ is also still failing for me:
Image 2022-02-01 at 5 44 28 PM

The response from the endpoint is:

{"msg":"Request failed with status code 404"}

@pettinarip
Copy link
Member Author

pettinarip commented Feb 2, 2022

@samajammin yes, probably this is a bit tricky to test because we are using just 1 Gatsby Cloud site to test 2 different envs.

So, right now the GC site (pettinarip-ethereum-org-website-dev) is setup to be used in Netlify context.

If you want to test the preview deploys (GC context), you need to update the GATSBY_FUNCTIONS_PATH to be /api.


This idea requires 2 GC sites.

  • 1 GC site for Netlify (ethereum-org-website-prod)
  • 1 GC site for the preview deploys (ethereum-org-website-dev)

We won't have a GC site that works with both hosting envs.

Let me know if this doesn't make sense to you and we can discuss it on a call.

@samajammin
Copy link
Member

samajammin commented Feb 2, 2022

Makes sense, so can't we set up this PR preview deploy to be the GC preview test (ethereum-org-website-dev)?

I suppose that was my assumption:

  • pettinarip-ethereum-org-website-dev to test Netlify functions context
  • ethereum-org-website-dev (i.e. this PR's preview deploy) to test Gatsby functions context

@pettinarip pettinarip force-pushed the functions-support-gc branch from 3237e62 to 5b72e28 Compare February 2, 2022 20:22
@github-actions github-actions bot added the dependencies 📦 Changes related to project dependencies label Feb 9, 2022
@samajammin
Copy link
Member

samajammin commented Feb 23, 2022

IIRC, some ENV variables are not working in Gatsby Cloud. This isn't a bug on our end - we're still waiting on Gatsby Cloud support for resolution here, correct @pettinarip? If so, could you please update this PR to a draft?

@minimalsm minimalsm added the Status: Blocked 🛑 This is blocked label Feb 28, 2022
@minimalsm minimalsm marked this pull request as draft February 28, 2022 17:43
@samajammin
Copy link
Member

Marking as blocked - still waiting on a response from Gatsby Cloud.

@pettinarip pettinarip force-pushed the functions-support-gc branch from 6dea794 to 6543f9b Compare March 7, 2022 22:23
@pettinarip pettinarip marked this pull request as ready for review March 7, 2022 23:12
@pettinarip pettinarip removed the Status: Blocked 🛑 This is blocked label Mar 7, 2022
@pettinarip
Copy link
Member Author

PR unblocked. Functions working in both envs now.

@pettinarip pettinarip requested a review from samajammin March 7, 2022 23:14
@samajammin
Copy link
Member

@pettinarip all functions are giving me a 500 on https://pettinarip-eth-org.netlify.app/en/ - they're working for you?

Copy link
Member

@samajammin samajammin left a comment

Choose a reason for hiding this comment

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

Working now!

@samajammin samajammin merged commit 7d6899e into ethereum:dev Mar 8, 2022
@minimalsm minimalsm mentioned this pull request Mar 22, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dependencies 📦 Changes related to project dependencies
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants