繁体   English   中英

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

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

几天以来,我试图让我的应用程序在 Heroku 上运行,但我遇到了 CORS 问题。 我阅读了 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错误。 感谢您的帮助这是我服务器中的代码:

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)})

谢谢你的尝试。 错误实际上是在我的前端文件中的请求中。 链接错误。 我只需要将我所有的' https://git.heroku.com/orientation-back.git/ '更改为' https '://orientation-back。

暂无
暂无

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

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