当节点应用程序部署到Heroku时,我设法使Node.js应用程序与Heroku Postgres数据库一起正常工作。但是,每次我更改代码时都必须部署到heroku有点麻烦,我希望能够在本地开发并从本地应用程序连接到数据库。
https://devcenter.heroku.com/articles/connecting-to-heroku-postgres-databases-from-outside-of-heroku
上面的文章并没有真正描述这是如何完成的,我不确定我需要做什么。
如果我尝试在本地运行我的应用程序并访问查询我的数据库的端点
testImplementation "org.robolectric:robolectric:4.0.2"
androidTestImplementation 'info.cukes:cucumber-android:1.2.5'
androidTestImplementation 'info.cukes:cucumber-picocontainer:1.2.5'
//androidTestImplementation 'com.android.support:support-annotations:26.1.0' // <-- match with the support lib version
androidTestImplementation 'com.android.support:support-annotations:27.1.1'
// testImplementation 'io.cucumber:cucumber-java:3.0.2'
// testImplementation 'io.cucumber:cucumber-junit:3.0.2'
// testImplementation 'io.cucumber:cucumber-jvm:3.0.2'
androidTestCompile('com.android.support:multidex-instrumentation:1.0.1') {
exclude group: 'com.android.support', module: 'multidex'
}
/////
}
如果我从heroku部署的应用程序访问相同的端点,它将正常工作。
这是我的应用
export const InputBox = styled.input`
/* This renders the input above... Edit */
display: flex;
width: 45%;
height: 2em;
margin-top: 1em;
background: linear-gradient(
360deg,
#b0a7e6 0%,
rgba(176, 167, 230, 0) 169.23%
);
border-radius: 5px;
border: 2px solid lavender;
color: #6e5dcc;
&:focus {
outline:none
border: 2px solid green;
} `}
`
render(
<div>
<input name="name" type="text"/>
<Button target="_blank" primary>click</Button>
</div>
)
答案 0 :(得分:1)
我认为您需要在本地计算机上更新process.env.DATABASE_URL。从该错误来看,当您要使用Heroku上托管的数据库时,DATABASE_URL似乎引用了localhost。
我了解您只想使用远程数据库。该错误表明您无法连接到127.0.0.1:5432。这是本地主机的IP地址,而不是远程数据库。您的代码由于某种原因试图连接到127.0.0.1:5432,而它应该尝试连接到远程数据库。
答案 1 :(得分:0)
您是否使用 dotenv 访问 process.env.DATABASE_URL ? 你需要 dotenv.config();为我工作。