thebatt
03/31/2022, 1:34 PMthebatt
03/31/2022, 2:59 PMthebatt
03/31/2022, 3:01 PMhanpolo
03/31/2022, 5:59 PMhanpolo
03/31/2022, 6:00 PMGreg Brimble | Cloudflare Pages
03/31/2022, 6:26 PMGreg Brimble | Cloudflare Pages
03/31/2022, 6:26 PMnpx wrangler pages dev public
hanpolo
04/01/2022, 2:41 AMGreg Brimble | Cloudflare Pages
04/01/2022, 7:20 AMMAXOUXAX
04/01/2022, 7:08 PMPOST /api/x/y 500 Internal Server Error (30.08ms)
[pages:err] POST /api/x/y: TypeError: Cannot read properties of undefined (reading 'get')
coming from that line of code if (!context.headers.get('content-type').includes('form'))
Sending the test request through Hoppscotch locally, here's the curl command equivalent of the request I'm sending, as you can see there is an header set:
bash
curl --request POST \
--url http://localhost:8788/api/x/y \
--header 'Content-Type: JSON' \
--data 'some json object'
Also, here's the wrangler command I used to serve my website locally: wrangler pages dev --proxy 8080 -- npm run serve
Walshy | Pages
04/01/2022, 7:34 PMheaders
come from Request however you're currently using it on the context. You should instead do if (!context.request.headers.get('content-type').includes('form'))
patrickheneise
04/01/2022, 9:00 PMfetch
on the Functions?Greg Brimble | Cloudflare Pages
04/01/2022, 10:54 PMIsaac McFadyen | YYZ01
04/02/2022, 1:31 AMIsaac McFadyen | YYZ01
04/02/2022, 1:31 AMTrickMatt
04/02/2022, 2:00 AMpatrickheneise
04/02/2022, 7:44 AMpatrickheneise
04/02/2022, 7:48 AMpatrickheneise
04/02/2022, 7:50 AMpatrickheneise
04/02/2022, 7:54 AMconst req = await fetch('https://api.sendgrid.com/v3/mail/send', {
method: 'POST',
body: JSON.stringify(email),
headers: {
Authorization: `Bearer ${env.SENDGRID_API_KEY}`,
'Content-Type': 'application/json'
}
})
Greg Brimble | Cloudflare Pages
04/02/2022, 8:50 AMwrangler pages dev
, or when you deploy to prod as well?Greg Brimble | Cloudflare Pages
04/02/2022, 8:51 AMpatrickheneise
04/02/2022, 12:46 PMpatrickheneise
04/02/2022, 12:47 PMIsaac McFadyen | YYZ01
04/02/2022, 1:59 PMfetch
api.Isaac McFadyen | YYZ01
04/02/2022, 1:59 PMWalshy | Pages
04/02/2022, 2:25 PM