How to deploy a SpringBoot\React Application to Heroku - reactjs

I am in the process of uploading an application I developed on my local PC to Heroku. It has a Springboot backend accessing a Postgresql database and a React\Axios front end.
I uploaded the source to GITHUB and created a project in Heroku and deployed from Heroku. I created the Postgresql database, deployed the Backend and Front end. The React Front end executes and paints the screen, but no data is sent from the backend. I do not think I have the proper pointers in the front end to the backend. Possibly the backend is not seeing the database. The backend did see the POSTGRESQL database locally as I tested with POSTMAN. Not sure how to test with POSTMAN with a remote database. Dataclips Query works within Heroku.
Any help with this would be appreciated.
React Front End Axios URL before:
export const USER_API_BASE_URL = "http://localhost:8080/api/v1/";
React Front End Axios URL after:
export const USER_API_BASE_URL =
"postgres://xmmazemfflgbkj:a323bc337c559fffd0ec7029daaf60f03712cdb1df41ca8629fe8429f0a7a607#ec2-54-85-113-73.compute-1.amazonaws.com:5432/d423nfcf5dbjf7";
Spring Boot application.properties before
spring.datasource.url=jdbc:postgresql://localhost:5432/budgettool
spring.datasource.username=postgres
spring.datasource.password=admin
Spring Boot application.properties after
spring.datasource.url=postgres://xmmazemfflgbkj:a323bc337c559fffd0ec7029daaf60f03712cdb1df41ca8629fe8429f0a7a607#ec2-54-85-113-73.compute-1.amazonaws.com:5432/d423nfcf5dbjf7
spring.datasource.username=xmmazemfflgbkj
spring.datasource.password=a323bc337c559fffd0ec7029daaf60f03712cdb1df41ca8629fe8429f0a7a607
SpringBootApplication.java
contains the following
public WebMvcConfigurer corsConfigurer() {
return new WebMvcConfigurer() {
#Override
public void addCorsMappings(CorsRegistry registry) {
registry.addMapping("/**")
.allowedOrigins("http://localhost:3000")
.allowedMethods("GET", "PUT", "POST", "PATCH", "DELETE", "OPTIONS");
}
};
Heroku Log
2022-03-25T13:35:51.002170+00:00 heroku[web.1]: State changed from crashed to starting
2022-03-25T13:35:54.059594+00:00 heroku[web.1]: Starting process with command `java -Dserver.port=13204 $JAVA_OPTS -jar target/budget-backend-postsql-0.0.1-SNAPSHOT.jar`
2022-03-25T13:35:54.935490+00:00 app[web.1]: Create a Procfile to customize the command used to run this process: https://devcenter.heroku.com/articles/procfile
2022-03-25T13:35:54.959996+00:00 app[web.1]: Setting JAVA_TOOL_OPTIONS defaults based on dyno size. Custom settings will override them.
2022-03-25T13:35:54.964400+00:00 app[web.1]: Picked up JAVA_TOOL_OPTIONS: -XX:+UseContainerSupport -Xmx300m -Xss512k -XX:CICompilerCount=2 -Dfile.encoding=UTF-8
2022-03-25T13:35:55.118429+00:00 app[web.1]: no main manifest attribute, in target/budget-backend-postsql-0.0.1-SNAPSHOT.jar
2022-03-25T13:35:55.259986+00:00 heroku[web.1]: Process exited with status 1
2022-03-25T13:35:55.302308+00:00 heroku[web.1]: State changed from starting to crashed
2022-03-25T15:25:55.884892+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=budget-program-backend.herokuapp.com request_id=69a08cfa-7635-4586-8454-5f91b4ccca8e fwd="35.136.227.81" dyno= connect= service= status=503 bytes= protocol=https
2022-03-25T15:25:56.285150+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=budget-program-backend.herokuapp.com request_id=4ad6b14b-ee7b-4dd0-9cee-ea9d7ef547a7 fwd="35.136.227.81" dyno= connect= service= status=503 bytes= protocol=https
Fixed some of the above in POM.XML
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<mainClass>com.places.Main</mainClass>
</configuration>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
New error:
2022-03-25T16:38:26.078846+00:00 heroku[web.1]: Process exited with status 1
2022-03-25T16:38:26.138596+00:00 heroku[web.1]: State changed from starting to crashed
2022-03-25T16:44:21.027515+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=budget-program-backend.herokuapp.com request_id=1b4650a2-c5f4-4fb6-8300-79e7309bc9fe fwd="35.136.227.81" dyno= connect= service= status=503 bytes= protocol=https
2022-03-25T16:44:21.202166+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=budget-program-backend.herokuapp.com request_id=593e9080-71e8-4e0a-9308-8ca4ff6107d2 fwd="35.136.227.81" dyno= connect= service= status=503 bytes= protocol=https

First, u can check Heroku logs on your backend application there should be an exception if the spring boot application can't access the Postgres server. If there is an exception related to accessing the SQL server you should check the JDBC connection string. I think you are missing "jdbc:" in your data source URL
"spring.datasource.url=postgres://xmmazemfflgbkj:a323bc337c559fffd0ec7029daaf60f03712cdb1df41ca8629fe8429f0a7a607#ec2-54-85-113-73.compute-1.amazonaws.com:5432/d423nfcf5dbjf7".Also you should try to test remote spring boot applications APIs with the postman durring the testing to avoid CORS issue.One more advice do not share real SQL credentional on any public website.

Related

Heroku app successfully deploying, but received application error when loading site

Application error
An error occurred in the application and your page
could not be served. If you are the application owner, check your logs
for details. You can do this from the Heroku CLI with the command
heroku logs --tail
How can i resolve this?
Heroku logs
2010-09-16T15:13:46.677020+00:00 app[web.1]: Processing PostController#list (for 208.39.138.12 at 2010-09-16 15:13:46) [GET]
2010-09-16T15:13:46.677023+00:00 app[web.1]: Rendering template within layouts/application
2010-09-16T15:13:46.677902+00:00 app[web.1]: Rendering post/list
2010-09-16T15:13:46.678990+00:00 app[web.1]: Rendered includes/_header (0.1ms)
2010-09-16T15:13:46.698234+00:00 app[web.1]: Completed in 74ms (View: 31, DB: 40) | 200 OK [http://myapp.heroku.com/]
2010-09-16T15:13:46.723498+00:00 heroku[router]: at=info method=GET path="/posts" host=myapp.herokuapp.com" fwd="204.204.204.204" dyno=web.1 connect=1ms service=18ms status=200 bytes=975
2010-09-16T15:13:47.893472+00:00 app[worker.1]: 2 jobs processed at 16.6761 j/s, 0 failed ...

Problem deploying a react app on heroku -- error code 503 on console

i'm currently uploading my Portfolio, in react, on Heroku, build succeeds but i get this error page with a code 503 in console...
Here is the error :
GET https://mpj-portfolio-app.herokuapp.com/favicon.ico 503 (Service Unavailable)
Seems to have something to do with Tailwind and/or the favicon displayed on the tab (which i changed, but then changed back to the original)
I also get these errors in the app logs
2021-10-21T09:46:40.806231+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=mpj-portfolio-app.herokuapp.com request_id=bd24e409-699a-4687-8871-4ef1b6023e7c fwd="193.253.212.196" dyno= connect= service= status=503 bytes= protocol=https
2021-10-21T09:46:41.308024+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=mpj-portfolio-app.herokuapp.com request_id=0b1515b1-74a1-49ca-9e79-d7b673ad435b fwd="193.253.212.196" dyno= connect= service= status=503 bytes= protocol=https
Please help ?
I found this tutorial :
https://betterprogramming.pub/how-to-deploy-your-react-app-to-heroku-aedc28b218ae
Really helpfull, now i just got to figure out how to load Tailwind to my page

Heroku app giving "status=404" and not showing up

I got my app successfully (or at least it seemed to be) uploaded to heroku. Everything said it was successful, but then when I try to hit the "Open App" button on that app's heroku page it returns with a 404 error.
2021-03-14T22:35:00.849056+00:00 app[web.1]: [2021-03-14 22:35:00 +0000] [5] [INFO] Using worker: sync
2021-03-14T22:35:00.852727+00:00 app[web.1]: [2021-03-14 22:35:00 +0000] [7] [INFO] Booting worker with pid: 7
2021-03-14T22:35:00.942754+00:00 heroku[web.1]: State changed from starting to up
2021-03-14T22:42:41.838136+00:00 heroku[router]: at=info method=GET path="/" host=cupboardcobble.herokuapp.com request_id=605b3d3a-55ac-458a-aa9b-d5e76a1a5331 fwd="73.80.9.120" dyno=web.1 connect=0ms service=3ms status=404 bytes=432 protocol=https
That is what it shows when I run "heroku logs --tail --app cupboardcobble" in the terminal. If I look up earlier in the log I see the "h10" code, but I have not been able to locate the possible reason for this. This is a react-redux based front end, and a flask based backend with docker. Any help would be really appreciated.

Deploying Express server&React client to Heroku fails; no error in the logs, just 404

I'm writing a simple client/server app and getting into an issue when deploying to Heroku. My code is here (currently at commit 11351f8e15a872e50595ad305eb4a935bba3a0d6) and I based it on this and this tutorial (both suggest the same directoy structure, just differ in the main package.json scripts).
At first, I got an error cannot access '/app/build/static/js/*.js', which I resolved by running this command (which neither of the tutorials mentioned :-/).
heroku config:set JS_RUNTIME_TARGET_BUNDLE=/app/client/build/js/*.js
I thought I was good, but no. Despite Heroku no longer complains, there is simply nothing out there, just 404. I bet it's something trivial, but I'm honestly running out of ideas. Please help.
2020-05-05T15:11:49.896205+00:00 app[api]: Set JS_RUNTIME_TARGET_BUNDLE config vars by user [...]
2020-05-05T15:11:49.896205+00:00 app[api]: Release v19 created by user [...]
2020-05-05T15:11:51.492041+00:00 app[web.1]: Going down, terminating child processes...
2020-05-05T15:12:00.850825+00:00 app[web.1]: Injecting runtime env into /app/client/build/static/js/2.e0399e74.chunk.js (from .profile.d/inject_react_app_env.sh)
2020-05-05T15:12:00.949574+00:00 app[web.1]: Injecting runtime env into /app/client/build/static/js/main.e25999d1.chunk.js (from .profile.d/inject_react_app_env.sh)
2020-05-05T15:12:01.041037+00:00 app[web.1]: Injecting runtime env into /app/client/build/static/js/runtime-main.b186b88b.js (from .profile.d/inject_react_app_env.sh)
2020-05-05T15:12:01.368403+00:00 app[web.1]: Starting log redirection...
2020-05-05T15:12:01.368798+00:00 app[web.1]: Starting nginx...
2020-05-05T15:12:01.632649+00:00 heroku[web.1]: State changed from starting to up
2020-05-05T15:12:16.518752+00:00 heroku[run.5999]: State changed from up to complete
2020-05-05T15:12:32.064267+00:00 heroku[router]: at=info method=GET path="/" host=bn-go.herokuapp.com request_id=8e4f6060-26e2-4283-8637-c79f09e61778 fwd="106.72.42.32" dyno=web.1 connect=1ms service=3ms status=404 bytes=403 protocol=https
2020-05-05T15:29:07.968532+00:00 heroku[router]: at=info method=GET path="/api/load" host=bn-go.herokuapp.com request_id=b1942d65-eac0-4873-ba4b-b07a41efe2b1 fwd="106.72.42.32" dyno=web.1 connect=0ms service=2ms status=404 bytes=403 protocol=https
Ugh, I figured it out. It was create-react-app-buildpack, which changed dyno setting from "npm start" to "bin/boot". I removed it and it all works fine.

Heroku giving me a 503 error but works on localhost

My /register is working perfectly on localhost but giving me a 503 error on heroku. Here's the error message.
Failed to load resource: the server responded with a status of 503 (Service Unavailable)
Here's the next message that appears below it (not sure if it's important or just shows that the app is breaking)
Error: [ngRepeat:dupes] Duplicates in a repeater are not allowed. Use 'track by' expression to specify unique keys. Repeater: error in registerError, Duplicate key: string: , Duplicate value: " "
And finally here's my heroku logs
2015-12-02T13:44:53.965876+00:00 heroku[router]: at=info method=GET path="/modules/aggregated.css" host=www.fillinfor.me request_id=54d7e7b0-037e-4147-a55b-4d66a838b2d8 fwd="69.23.66.60" dyno=web.1 connect=0ms service=3ms status=304 bytes=127
2015-12-02T13:45:00.776609+00:00 heroku[router]: at=error code=H12 desc="Request timeout" method=POST path="/register" host=www.fillinfor.me request_id=359d5d68-a083-4349-b4f6-c0198259d0e3 fwd="69.23.66.60" dyno=web.1 connect=0ms service=30001ms status=503 bytes=0
Update:
Here's the registration page url http://www.fillinfor.me/?#!/join
here it is on localhost http://localhost:3000/?#!/join

Resources