/

Vercel Serverless functions

https://vercel.com/docs/concepts/functions/serverless-functions
On this page
  • Basic example
  • Enabling CORS

Basic example

With JavaScript

ts
// /api/test.js
const handler = (request, response) => {
response.status(200).json({
body: request.body,
query: request.query,
cookies: request.cookies,
})
};
export default handler;

With TypeScript

ts
// /api/test.ts
import { VercelApiHandler } from './types';
const handler: VercelApiHandler = (request, response) => {
response.status(200).json({
body: request.body,
query: request.query,
cookies: request.cookies,
})
};
export default handler;

Enabling CORS

vercel.com/support/...ble-cors

Edit this page
Want to make your own site like this?
Try gatsby-theme-code-notes by Zander Martineau.
Notes on code. My second brain, by Zander Martineau.