【发布时间】:2020-02-17 15:56:45
【问题描述】:
我有一个 React.js 应用程序,我在一个 cPanel 上托管,该应用程序不允许在应用程序中使用后端。想知道我是否可以在没有后端的情况下让 sendgrid 工作?以前有人让这个工作吗?
我目前收到以下错误:
Access to fetch at 'https://api.sendgrid.com/v3/mail/send' from origin '
https://angelospizzaharvard.com' has been blocked by CORS policy: Response
to preflight request doesn't pass access control check: The 'Access-Control-
Allow-Origin' header has a value 'https://sendgrid.api-docs.io' that is not
equal to the supplied origin.
Have the server send the header with a valid
value, or, if an opaque response serves your needs, set the request's mode
to 'no-cors' to fetch the resource with CORS disabled.
Navbar.js:427 TypeError: Failed to fetch
【问题讨论】:
-
这绝对是可能的,但实际上根本不推荐,因为您需要将您的电子邮件服务器身份验证凭据暴露给前端,这是一个很大的禁忌
-
比尔,如果我将电子邮件服务器登录凭据隐藏在 .env 文件中会怎样?
-
@Eric K。它仍然会被公开,因为它需要随请求一起发送。
-
@EricK.env 文件仅将秘密值保留在您的 git 存储库之外,它们仍然暴露在生产中的前端