Sendgrid API - JSON call

只谈情不闲聊 提交于 2019-12-01 10:54:54

The issue is that SendGrid does not support jsonp.

Unfortunately, switching to plain JSON will not work either, as SendGrid has no CORS headers and browsers will not allow you to access the pages. In short you cannot make AJAX requests dorectly to SendGrid.

However, generally this is for the better as all SendGrid endpoints require authentication and having your username and password in an AJAX request would allow users to take them and then use them to send email.

To get these stats on the frontend, you'll need a server to get them and output them on your domain or a domain with CORS allowances.

Here comes a one click solution!

  1. Deploy your instance of SendGrid Proxy to Heroku
  2. Use {your-sendgrid-proxy}.herokuapp.com instead of api.sendgrid.com
  3. Done (Really)

How it works:

  1. It creates a node powered http proxy using express-http-proxy
  2. It adds needed headers such as Authorization and Content-Type
  3. It overrides Access-Control-Allow-Origin to * to make your browser CORS warning free

See how the magic is working. Feedback is welcome!

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!