简体   繁体   English

将应用程序部署到 heroku. 节点后,来自 api 请求的 401 Unauthorized Access。 表示。 axios

[英]401 Unauthorized Access from api request after deploying app to heroku. node. express. axios

My landing page works, but when you go to the home page my app makes a GET request to an API ( https://ridb.recreation.gov/docs#/ for info).我的登录页面有效,但是当您 go 到主页时,我的应用程序向 API 发出 GET 请求( https://ridb.recreation.gov/docs#/获取信息)。 The pages then stalls.然后页面停止。 The heroku logs show that the API rejected my request with a 401 unauthorized access. heroku 日志显示 API 以 401 未授权访问拒绝了我的请求。 I have my env.我有我的环境。 variables set up in heroku and the app was working fine locally.在 heroku 中设置的变量和应用程序在本地运行良好。

here is some of the response from the api:以下是 api 的部分回复:

2020-11-14T00:13:10.041374+00:00 app[web.1]:   response: {
2020-11-14T00:13:10.041375+00:00 app[web.1]:     status: 401,
2020-11-14T00:13:10.041375+00:00 app[web.1]:     statusText: 'Unauthorized',
2020-11-14T00:13:10.041376+00:00 app[web.1]:     headers: {
2020-11-14T00:13:10.041376+00:00 app[web.1]:       'content-type': 'application/json',
2020-11-14T00:13:10.041376+00:00 app[web.1]:       'content-length': '33',
2020-11-14T00:13:10.041377+00:00 app[web.1]:       connection: 'close',
2020-11-14T00:13:10.041377+00:00 app[web.1]:       server: 'Server',
2020-11-14T00:13:10.041378+00:00 app[web.1]:       date: 'Sat, 14 Nov 2020 00:13:10 GMT',
2020-11-14T00:13:10.041378+00:00 app[web.1]:       'x-amz-apigw-id': 'V-IbcGM5oAMF7jw=',
2020-11-14T00:13:10.041378+00:00 app[web.1]:       'strict-transport-security': 'max-age=31536000; includeSubdomains; always',
2020-11-14T00:13:10.041379+00:00 app[web.1]:       'cache-control': 'max_age=600,public,stale-if-error=3600',
2020-11-14T00:13:10.041384+00:00 app[web.1]:       'x-content-type-options': 'nosniff',
2020-11-14T00:13:10.041385+00:00 app[web.1]:       'x-frame-options': 'SAMEORIGIN',
2020-11-14T00:13:10.041385+00:00 app[web.1]:       'x-xss-protection': '1; mode=block',

and here is my axios code:这是我的 axios 代码:

我的 axios api 请求代码

I tried adding some 'access-control-allow-origin' options but didn't work.我尝试添加一些“access-control-allow-origin”选项但没有用。

Thanks to all who looked at my question.感谢所有看过我的问题的人。 After skimming through the logs I found out Heroku added another set of quotes (' ') on my.env variable that caused the error.浏览日志后,我发现 Heroku 在导致错误的 my.env 变量上添加了另一组引号 (' ')。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM