Home > Mobile >  Heroku Go app is no longer working after a few minutes
Heroku Go app is no longer working after a few minutes

Time:05-21

I had trouble getting my React app to run on GitHub pages, so I chose to try and serve the files on my Go backend which is on Heroku. At first I was serving the React app through the main Go backend, which did serve the React app successfully but none of my other routes would work after that in the Go app, the routes needed for my React app to operate.

So I chose to create a new Heroku Go app and separate the backend and frontend on different Heroku Go apps. The frontend Go app is running fine, but the backend will intermittently work. I understand Heroku free apps go into a sleep state with a period of inactivity, but I am literally talking about the app being online for a few minutes, and then all of sudden just switching back to the default mode of saying "no such app"

Frontend Heroku Go app:

// Route: Delete Graph from database
func RouteDefault(w http.ResponseWriter, r *http.Request, p httprouter.Params) {
    http.ServeFile(w, r, "static/index.html")
}

func main() {

    port := os.Getenv("PORT")
    if port == "" {
        port = "9000" // Default port if not specified
    }

    // HTTPRouter Settings and Routes
    router := httprouter.New()
    router.GET("/", RouteDefault)

    // if not found look for a static file
    static := httprouter.New()
    static.ServeFiles("/*filepath", http.Dir("static"))
    router.NotFound = static

    handler := cors.AllowAll().Handler(router)
    fmt.Println(http.ListenAndServe(":" port, handler))
}

Backend Heroku Go app:

func main() {
    // BasicAuth username and password
    user := ""
    pass := ""

    port := os.Getenv("PORT")
    if port == "" {
        port = "9000" // Default port if not specified
    }

    DefaultUser()

    // HTTPRouter Settings and Routes
    router := httprouter.New()
    router.POST("/login/", BasicAuth(RouteLogin, user, pass))
    router.POST("/upload/", JWTAuth(RouteUpload))
    router.POST("/graph/", JWTAuth(RouteGetGraph))
    router.GET("/autologin/", JWTAuth(RouteAutoLogin))

    handler := cors.AllowAll().Handler(router)
    fmt.Println(http.ListenAndServe(":" port, handler))
}

Frontend: https://grafulatordemo.herokuapp.com/ Backend: https://grafulator.herokuapp.com/

CodePudding user response:

run the command: heroku apps -A and share the relevant output so it can be troubleshooted

CodePudding user response:

The problem was on heroku's end, contacting their support team resolved it.

  • Related