Handling requests with Gatsby
Gatsby Functions
Gatsby Functions provides an Express-like(opens in a new tab) architecture that simplifies building Node.js APIs.
Gatsby Functions can use the ClerkExpressWithAuth
and ClerkExpressRequireAuth
middlewares from the Clerk Node SDK as shown below.
src/api/clerk.jsimport { ClerkExpressRequireAuth } from '@clerk/clerk-sdk-node'; const requireAuth = ClerkExpressRequireAuth(); export default async function clerkHandler(req, res) { await new Promise((resolve, reject) => { requireAuth(req, res, result => { if (result instanceof Error) { reject(result); } resolve(result); }); }) res.json(`Hi from Gatsby Functions`) }
For more information on how to use Express middlewares in Gatsby, refer to the Gatsby official documentation(opens in a new tab).
Last updated on October 2, 2023