├── .gitignore ├── netlify.toml ├── index.html └── functions └── corgis.js /.gitignore: -------------------------------------------------------------------------------- 1 | # Local Netlify folder 2 | .netlify 3 | -------------------------------------------------------------------------------- /netlify.toml: -------------------------------------------------------------------------------- 1 | [build] 2 | functions = "functions" 3 | publish = "." 4 | build = "# no build command" 5 | 6 | [[redirects]] 7 | from = "/api/*" 8 | to = "/.netlify/functions/:splat" 9 | status = 200 10 | -------------------------------------------------------------------------------- /index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 |
4 | 5 | 6 |11 | You can’t make requests to this API from another website. I need this API 12 | to exist so I can teach people how to work around this limitation using 13 | serverless functions. 14 |
15 |To use this, send a GET request to:
16 |17 | https://no-cors-api.netlify.app/api/corgis 18 |19 |
The API returns JSON.
20 | 21 | 22 | -------------------------------------------------------------------------------- /functions/corgis.js: -------------------------------------------------------------------------------- 1 | exports.handler = async () => ({ 2 | statusCode: 200, 3 | headers: { 4 | 'Content-Type': 'application/json', 5 | }, 6 | body: JSON.stringify([ 7 | { 8 | id: 'Zwvxj3ytTHc', 9 | name: 'Dögg Barkardóttir', 10 | favoriteSong: 'Bjärk — Play Dead', 11 | }, 12 | { 13 | id: 'yxmNWxi3wCo', 14 | name: 'Miz Barkie', 15 | favoriteSong: 'Corgi B — WAP (Wiggly-Ass Puppy)', 16 | }, 17 | { 18 | id: 'KQN500iE8KA', 19 | name: 'Walden', 20 | favoriteSong: 'Death Cab For Corgi — I Will Follow You Into The Park', 21 | }, 22 | { 23 | id: 'J5feaur-y6I', 24 | name: 'Atticus', 25 | favoriteSong: 'Furrell Williams — Yappy', 26 | }, 27 | { 28 | id: 'uc3JhSWITMo', 29 | name: 'Millie', 30 | favoriteSong: 'Anderson .Pawk — Come Down', 31 | }, 32 | { 33 | id: 'cX-KEISwDIw', 34 | name: 'Admiral Ackbark', 35 | favoriteSong: 'Splootie & The Blowfish — Only Wanna Steal Your Food', 36 | }, 37 | ]), 38 | }); 39 | --------------------------------------------------------------------------------