π Welcome to Green Webhook! π
Green Webhook is a proxy or gateway between two systems that intelligently chooses which endpoint to send a webhook event to in order to location shift or time shift (coming soon) compute workloads to the endpoint with the lowest carbon intensity. It uses the Carbon Aware SDK to check the impact of an increased demand on the electricity grid for the relevant locations.
By deploying your workload to multiple regions and configuring each endpoint along with its location within a Green Webhook you can reduce the carbon emissions caused by your workload.
Currently Green Webhook supports only Azure regions but as the Carbon Aware SDK adds more support for other locations Green Webhook will be able to support them too.
Green Webhook is built on RedwoodJS and uses:
- Create a NextJS app by running
npx create-next-app nextjs-blog --use-npm --example "https://github.com/vercel/next-learn/tree/master/basics/api-routes-starter"
- Create
pages/api/user.js
with:
export default function handler(req, res) {
res.status(200).json({ name: "John Doe" });
}
- In a terminal run
npm run dev
- Install Ngrok
- In a terminal run
ngrok http 3000
- Copy the URL output by Ngrok and add
/api/user
to the end - Log in to https://greenwebhook.netlify.app and create a new webhook
- Paste the URL from step 6 into the destination
- Click Save
- Click on the
Invocation URI
link to trigger the webhook - Confirm that the response is
200
and contains JSON{ name: "John Doe" }
Currently the Carbon Aware SDK only supports a limited list of locations but when more locations are supported then we will be able to allow you to put in the location where your computer or laptop is running in order to determine if it is the location with the lowest carbon intensity.
Prerequisites
- Green Webhook is built with Redwood and requires Node.js (>=14.19.x <=16.x) and Yarn (>=1.15)
- Are you on Windows? For best results, follow our Windows development setup guide
Start by installing dependencies:
yarn install
Whilst that is running, create a file in the root folder called .env
and copy the following into it:
# Used to encrypt/decrypt session cookies. Change this value and re-deploy to log out all users of your app at once.
# Run yarn redwood generate secret and copy the value below
SESSION_SECRET=YOUR_SESSION_SECRET
# SendInBlue secret for reset password emails to work (optional)
# Requires setting up a free account at https://www.sendinblue.com/
SEND_IN_BLUE_KEY=YOUR_SENDINBLUE_SECRET
SEND_IN_BLUE_EMAIL=YOUr_SENDINBLUE_EMAIL_ADDRESS
DEPLOY_URL=http://localhost:8910
# Create a free database via https://railway.app and replace YOUR_RAILWAY_DB_URL bellow with the connection URL
DATABASE_URL="YOUR_RAILWAY_DB_URL"
CARBON_AWARE_API_BASE_URI="https://carbon-aware-api.azurewebsites.net"
# Run yarn redwood generate secret and copy the value below
SCHEDULED_WEBHOOKS_API_KEY=YOUR_SCHEDULED_WEBHOOK_SECRET_KEY
Replace YOUR_SESSION_SECRET
with the secret generated by running yarn rw generate secret
.
Replace YOUR_SCHEDULED_WEBHOOK_SECRET_KEY
with the secret generated by running yarn rw generate secret
a second time.
Create a free database via https://railway.app and copy the connection URL and replace YOUR_RAILWAY_DB_URL
with it
If you want to be able to send emails to reset passwords then you will need to create a SendInBlue account and create an API key and replace SEND_IN_BLUE_KEY
with the API key.
Now when yarn install
is finished you're ready to create the database tables in your Railway database.
yarn redwood prisma migrate dev
Once this finishes you should see tables appear in the database in Railway
Now you can run the app locally:
yarn rw dev
Your browser should automatically open to http://localhost:8910 where you'll see the Home page.
If you want to run scheduled webhooks you will need to periodically send a GET
request to http://localhost:8910/.netlify/functions/schedule
with the x-api-key
header set to the YOUR_SCHEDULED_WEBHOOK_SECRET_KEY
secret you created above.
Don't know what your data models look like? That's more than ok β Redwood integrates Storybook so that you can work on design without worrying about data. Mockup, build, and verify your React components, even in complete isolation from the backend:
yarn rw storybook