StephenGrider / FullstackReactCode

Companion repo to https://www.udemy.com/node-with-react-fullstack-web-development
1.39k stars 1.17k forks source link

SendGrid Test Integration with local tunnel not working. #34

Closed udithv closed 6 years ago

udithv commented 6 years ago

Hi Stephen,

When I tried integrating sendgrid event notification with localtunnel. It doesn't seem to work. I have tested the localtunnel proxy link seperately and it works fine. The sendgrid event notification also works fine as I tested it with an online service and I can confirm it is sending a sample POST request.

It doesn't work for complete source code of application as well. To reproduce the problem, checkout the testing webhooks branch. and install the dependencies and run the server. then in the sendgrid mail settings , Event notification paste the proxy localtunnel link and then click 'Test Your Integration'. You will see that the req.body is not getting logged in your console.

udithv commented 6 years ago

Hi Stephen, I solved it. You must enable CORS on your server in development. You can do it by the following code.

if(process.env.NODE_ENV !== 'production') {
    app.use(function(req, res, next) {
        res.header("Access-Control-Allow-Origin", "*");
        res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
        next();
      });
}

And also use a service like webhook.site rather than localtunnel.me