我已经在 Heroku 上托管了我的前端和后端。我通过 heroku 设置了一个 mysql 数据库,然后推送了指向部署数据库和链接的版本。我的数据库充满了数据和设置。
但是在我的应用程序上,我每次调用都会遇到“无法获取”错误。
我想我有几个问题。
目前我的 application.properties 位于我的 .gitignore 中。我是否需要将其删除以便我的 Heroku 环境可以看到链接?
我该如何解决这个问题?邮递员从不回复电话。
我设置正确吗?
调用前端:
const fetchUsers = async () => {
try {
const response = await fetch('http://ec2-34-225-27-237.compute-1.amazonaws.com:8080/users');
if (response.ok) {
const userData = await response.json();
setUsers(userData);
} else {
throw new Error('Failed to fetch users');
}
} catch (error) {
console.error('Error fetching users:', error);
}
};
应用程序.属性
spring.jpa.hibernate.ddl-auto=update
spring.datasource.url=jdbc:postgresql://ec2-34-225-27-237.compute-1.amazonaws.com:5432/dadlhgoflf7mau
spring.datasource.username=REDACTED
spring.datasource.password=REDACTED
keycloak.realm=jcmm
spring.datasource.driver-class-name=org.postgresql.Driver
Heroku 提供的凭证
Host
ec2-34-225-27-237.compute-1.amazonaws.com
Database
dadlhgoflf7mau
User
REDACTED
Port
5432
Password
REDACTED
URI
postgres://username:[email protected]:5432/dadlhgoflf7mau
我期望的只是干净的通话。大多数只是拉动整个桌子的调用。
我尝试了多种不同的 application.properties 配置。
您不应该将 application.properties 放在 .gitignore 中。 heroku 需要它来访问重要的凭据,并且属性文件将包含重要的动态应用程序相关信息。
Heroku 凭证经常轮换,因此对它们进行硬编码可能会导致您频繁查找更新的凭证并在应用程序中进行更改以进行开发。在 Heroku 上,当您部署数据库时,它会创建一些环境变量,例如:
spring:
datasource:
url: ${JDBC_DATABASE_URL}
username: ${JDBC_DATABASE_USERNAME}
password: ${JDBC_DATABASE_PASSWORD}