├── .gitignore ├── _redirects ├── package.json ├── netlify └── functions │ ├── hello.ts │ └── pets.ts └── index.html /.gitignore: -------------------------------------------------------------------------------- 1 | .env 2 | node_modules 3 | .netlify 4 | -------------------------------------------------------------------------------- /_redirects: -------------------------------------------------------------------------------- 1 | /api/* /.netlify/functions/:splat 200 2 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "dependencies": { 3 | "@netlify/functions": "^0.9.0" 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /netlify/functions/hello.ts: -------------------------------------------------------------------------------- 1 | import { Handler } from '@netlify/functions'; 2 | 3 | export const handler: Handler = async (event) => { 4 | const { name = 'world' } = event.queryStringParameters; 5 | 6 | return { 7 | statusCode: 200, 8 | body: `hello ${name}!`, 9 | }; 10 | }; 11 | -------------------------------------------------------------------------------- /netlify/functions/pets.ts: -------------------------------------------------------------------------------- 1 | import { Handler } from '@netlify/functions'; 2 | 3 | export const handler: Handler = async () => { 4 | const pets = [ 5 | { 6 | id: 1, 7 | name: 'Fluffy', 8 | type: 'dog', 9 | }, 10 | { 11 | id: 2, 12 | name: 'Mittens', 13 | type: 'gerbil', 14 | }, 15 | { 16 | id: 3, 17 | name: 'Bruiser', 18 | type: process.env.SECRET_VALUE, 19 | }, 20 | ]; 21 | 22 | return { 23 | statusCode: 200, 24 | headers: { 25 | 'Content-Type': 'application/json', 26 | }, 27 | body: JSON.stringify(pets), 28 | }; 29 | }; 30 | -------------------------------------------------------------------------------- /index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 |
4 | 5 | 6 | 7 |