最新消息: 电脑我帮您提供丰富的电脑知识,编程学习,软件下载,win7系统下载。

在Heroku上表达+反应CORS

IT培训 admin 14浏览 0评论

在Heroku上表达+反应CORS

这是错误:

Access to XMLHttpRequest at '' 
from origin '' has been blocked by CORS policy: No 'Access- 
Control-Allow-Origin' header is present on the requested resource.

但是我已经将原点包含在cors中:

const app = express();
app.use(
  cors({
    origin: process.env.ORIGIN,
    optionsSuccessStatus: 200,
    credentials: true,
  })
);

process.env.ORIGIN为

我已经尝试过heroku local,我认为它在本地的heroku上运行代码,并且一切正常。对于我的客户,我使用“ yarn build”然后“ serve -d build“在本地提供文件,并且可以使用。

不过这是我突然想起我运行heroku重新启动和heroku日志--tail

2020-05-09T01:57:28.971077+00:00 heroku[web.1]: Restarting
2020-05-09T01:57:28.987996+00:00 heroku[web.1]: State changed from up to starting
2020-05-09T01:57:35.626755+00:00 app[web.1]: Server is running on port 41637
2020-05-09T01:57:35.629379+00:00 app[web.1]: [db] Cannot read property 'split' of null
2020-05-09T01:57:36.571910+00:00 heroku[web.1]: State changed from starting to up

以及我提出要求时

2020-05-09T02:00:04.559800+00:00 heroku[router]: at=error code=H12 desc="Request timeout" 
method=GET path="/api/products/list" host=cheapandnice-backend.herokuapp 
request_id=98822b44-b339-48ec-b33d-c7dd91e8a380 fwd="186.168.187.244" dyno=web.1 connect=1ms 
service=30000ms status=503 bytes=0 protocol=http

我正在使用Mongo Atlas

回答如下:

好吧,事实证明这不是CORS问题。 Heroku日志--tails显示此

2020-05-09T01:57:35.629379+00:00 app[web.1]: [db] Cannot read property 'split' of null

当我在heroku中配置ENV变量时,我用简单的引号引起来

'mongodb+srv://...'

我删除了引号,现在可以使用

在Heroku上表达+反应CORS

这是错误:

Access to XMLHttpRequest at '' 
from origin '' has been blocked by CORS policy: No 'Access- 
Control-Allow-Origin' header is present on the requested resource.

但是我已经将原点包含在cors中:

const app = express();
app.use(
  cors({
    origin: process.env.ORIGIN,
    optionsSuccessStatus: 200,
    credentials: true,
  })
);

process.env.ORIGIN为

我已经尝试过heroku local,我认为它在本地的heroku上运行代码,并且一切正常。对于我的客户,我使用“ yarn build”然后“ serve -d build“在本地提供文件,并且可以使用。

不过这是我突然想起我运行heroku重新启动和heroku日志--tail

2020-05-09T01:57:28.971077+00:00 heroku[web.1]: Restarting
2020-05-09T01:57:28.987996+00:00 heroku[web.1]: State changed from up to starting
2020-05-09T01:57:35.626755+00:00 app[web.1]: Server is running on port 41637
2020-05-09T01:57:35.629379+00:00 app[web.1]: [db] Cannot read property 'split' of null
2020-05-09T01:57:36.571910+00:00 heroku[web.1]: State changed from starting to up

以及我提出要求时

2020-05-09T02:00:04.559800+00:00 heroku[router]: at=error code=H12 desc="Request timeout" 
method=GET path="/api/products/list" host=cheapandnice-backend.herokuapp 
request_id=98822b44-b339-48ec-b33d-c7dd91e8a380 fwd="186.168.187.244" dyno=web.1 connect=1ms 
service=30000ms status=503 bytes=0 protocol=http

我正在使用Mongo Atlas

回答如下:

好吧,事实证明这不是CORS问题。 Heroku日志--tails显示此

2020-05-09T01:57:35.629379+00:00 app[web.1]: [db] Cannot read property 'split' of null

当我在heroku中配置ENV变量时,我用简单的引号引起来

'mongodb+srv://...'

我删除了引号,现在可以使用

与本文相关的文章

发布评论

评论列表 (0)

  1. 暂无评论