0

I recently started working with Angular and created a pwa that allowed users in my board gaming club to submit results from their games. The end result is an email containing the form info sent to myself and the league manager. The form works great but as soon as I installed the mailgun package and tried to use the example code

var mailgun = require('mailgun-js')({apiKey: api_key, domain: domain});

I started to get a bunch of the following for various modules that I assume are dependencies. I looked in the node-modules folder and the pac-resolver is there and it looks like it's in good order. I received around 20 such errors for various modules. I have no idea how to fix this or what the root cause is. Any suggestions would be greatly appreciated.

[ng] ERROR in ./node_modules/pac-resolver/dnsResolve.js
[ng] Module not found: Error: Can't resolve 'dns' in 'C:\Users\Phil\src\iw40klv2\node_modules\pac-resolver'
German Quinteros
  • 1,870
  • 9
  • 33
user1572
  • 33
  • 4

1 Answers1

0

You can’t make authenticated requests to the mailgun api from frontend javascript code running in a browser. the mailgun api intentionally doesn’t support that. And if you do, you will get Status code 0 which indicates a CORS failure.

NOTE: If used in the browser, a proxy is required to communicate with the Mailgun api due to cors limitations. Also, do not publish your private api key in frontend code.

Mailgun API: Request header field Authorization is not allowed by Access-Control-Allow-Headers

https://github.com/angular/angular/issues/22022

HoseinGhanbari
  • 1,058
  • 1
  • 11
  • 23