【发布时间】:2019-08-17 21:07:16
【问题描述】:
我需要部署一个应用程序。我使用 React JS、Node JS 和 Mongodb atlas 来做到这一点。我试图在 Heroku 上部署它,但是当我在线尝试时无法访问我的数据库(在本地开发人员上工作正常)。使用 Heroku 访问我的数据库的好的语法是什么?
网站链接:https://teachonline.herokuapp.com/
链接到我的github:https://github.com/romainbor/eteach
我尝试了很多不同的语法来访问我的数据库,但总是失败。
我将代码原样放在本地开发人员中。
export const register = (user_name, password, email, category, skills, description, dispatch) => {
const data = {
user_name,
password,
description,
email,
category,
skills
};
let myHeaders = new Headers();
myHeaders.append("Content-type", "application/json");
myHeaders.append("Authorization", "Bearer "+localStorage.getItem('tokenJWT'));
fetch ('http://localhost:3001/user',
{
method:'POST',
mode: "cors",
headers : myHeaders,
body: JSON.stringify(data)
})
.then(response => response.json())
.catch(error => (error));
return{
type: "REQUEST_REGISTER",
payload: {}
}
};
我的客户端文件夹中的 package.json
"proxy": "http://localhost:5000"
如果我删除代理线路,我的应用程序在线但我永远无法访问我的数据库,因此我的应用程序无法使用。 如果我把代理行我得到“无效的主机头”
所以我误解了一些东西,但我不知道到底是什么
【问题讨论】:
标签: node.js reactjs heroku web-deployment