简体   繁体   English

我在 Heroku 上部署了我的应用程序,但后来我遇到了 cors 问题

[英]I deployed my app on Heroku but then I have cors problems

Since several days now I'm trying to make my app work on Heroku, but I have CORS problem.几天以来,我试图让我的应用程序在 Heroku 上运行,但我遇到了 CORS 问题。 I read the package cors documentation and I think I'm doing it right, but you can see my back-end here: https://github.com/Karlus44/orientation-back (I'll paste the relevant code) You can also find my front-end here: https://github.com/Karlus44/orientation-front and see that when you go to my app (here: https://orientation-front.herokuapp.com/ ) you have some CORS errors.我阅读了 package cors 文档,我认为我做对了,但是你可以在这里看到我的后端: Z5E056C500A1C4B6A7110B50D807BADE45Zlu -backIorientation also find my front-end here: https://github.com/Karlus44/orientation-front and see that when you go to my app (here: https://orientation-front.herokuapp.com/ ) you have some CORS错误。 Thanks for any help Here is the code in my server:感谢您的帮助这是我服务器中的代码:

const express = require('express');
const bcrypt = require('bcrypt-nodejs');
const cors = require('cors');
const multer = require('multer');

//many declarations


const app = express();

app.use(express.urlencoded({extended: false}));
app.use(express.json());

var corsOptions = {
  origin: 'https://orientation-front.herokuapp.com',
  methods: 'GET,POST',
  allowedHeaders: 'Content-Type',
  optionsSuccessStatus: 200
}


app.options('*', cors(corsOptions));



app.get('/',cors(corsOptions), (req,res)=>{
  return db('utilisateurs').count('id')
  .then(data => res.json(data));
})

//example of request

app.post('/signin', cors(corsOptions), (req,res) => {signin.handleSignin(req,res, db, bcrypt)})

thanks for trying.谢谢你的尝试。 The error was in fact in my requests in my front files.错误实际上是在我的前端文件中的请求中。 The link was wrong.链接错误。 I just needed to change all my ' https://git.heroku.com/orientation-back.git/ ' into ' https://orientation-back.herokuapp.com/ '我只需要将我所有的' https://git.heroku.com/orientation-back.git/ '更改为' https '://orientation-back。

暂无
暂无

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

相关问题 当我在 heroku 中部署我的应用程序时,获取 html 时出错 - Error getting html when I deployed my app in heroku 对于部署在 heroku 上的 Angular 应用程序,我该如何处理 CORS 问题? - How do I deal with CORS problem for Angular app deployed on heroku with a Postgres express backend? I've deployed a nodejs api to Heroku and a React app to my personal site and I'm getting cors errors but going to the api url directly gets response? - I've deployed a nodejs api to Heroku and a React app to my personal site and I'm getting cors errors but going to the api url directly gets response? 我在 Heroku 上部署了一个快速应用程序,但出现 404(未找到)错误 - I have an express app deployed on Heroku but I have 404 (not found) error 有没有办法确保我已部署 heroku 的服务/应用程序在更新期间保持运行? - Is there a way to ensure that a service/app that I have deployed heroku, stays running during an update? 在heroku上部署我的nodejs应用程序后出现错误 - i have an error after deploying my nodejs app on heroku 为什么在将我的Sails应用程序部署到Heroku之后,为什么无法在屏幕上显示某些自定义CSS归属 - why after I deployed my sails app on Heroku, some custom css attribution can not show on the screen 我在Heroku上部署了我的节点应用程序,想要启用Gzip压缩,有什么提示吗? - I deployed my node app on Heroku and want to enable Gzip compression, any tips? 部署到heroku时,如何使我的node / socket.io应用使用正确的端口? - How do I get my node/socket.io app to use the correct port when deployed to heroku? Node.js cors 源自部署在 heroku 上的应用程序 - Node.js cors origins from app deployed on heroku
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM