【发布时间】:2021-02-25 20:36:22
【问题描述】:
我刚刚按照文档将我的 Strapi API 部署到生产环境:https://strapi.io/documentation/v3.x/deployment/heroku.html
通过从其他来源发出 POST 请求,我收到此错误:
由于我的 API 最终在开发中工作(本地主机到本地主机),我认为问题与 CORS 有关,如果是,那就是我在 API 上设置的 cors 配置:
config/env/production/security.json:
{
"cors": {
"enabled": true,
"origin": "*"
}
}
config/env/production/middleware.js:
module.exports = {
settings: {
cors: {
enabled: true,
origin: "*",
},
},
};
【问题讨论】:
-
浏览器在 devtools 控制台中记录的确切错误消息是什么?
-
附带说明:每个人都应该首先探索的是在您的项目上运行
npm run dev。修改模型和路线后,这清除了我使用 Strapi 的 405 错误。
标签: api heroku graphql cors strapi