0

I built small go app, which I run locally using the following

// +build !appengine

package main

import (
    "fmt"
    "net/http"

    "github.com/Test/test/server"
)

func main() {
    r := server.Router()

    fmt.Println("Started Server")

    http.ListenAndServe("localhost:8182", r)
}

I deployed this some ago to Google AppEngine, and the above doesn't work, so I created this for Google AppEngine:

// +build appengine

package main

import (
    "net/http"

    "github.com/Test/test/server"
    "google.golang.org/appengine"
)

func init() {
    r := server.Router()

    appengine.Main()

    http.Handle("/", r)
}

I use the following in app.yaml

handlers:
- url: /.*
  script: _go_app
  secure: always
  redirect_http_response_code: 301

The app deploys fine, the Google Cloud Console says it is running, but all I get is "404 page not found", which is not any of the handlers that I built. AppEngine reports no errors, I only see 404 in the logs, digging deeper in the logs I find that some things mention the go app: urlMapEntry: "_go_app".

I am using go-chi router:

func Router() *chi.Mux {
    r := chi.NewRouter()

    // home
    r.Get("/", handlers.RootHandler)

    // api
    r.Route("/api", func(r chi.Router) {
        r.Get("/*", handlers.NotSupportedAPIHandler)
    })

    r.Get("/*", handlers.RootHandler)


    })
    return r
}

But not matter which url I enter, I do not see that the RootHandler is getting used, because it would return an HTML file. When I try to access /api, I also not do see the NotSupportedAPIHandler picking it up, since that would return a status 404 with a JSON response.

The strange thing is that a while back the code worked, I got the HTML file served, using the go_app, using the go-chi router. Now, all I get is 404 page not found.

The app is running fine locally.

How can I debug this? Is there any place where I can see what is going wrong or how app.yaml is routing this in such a way that it finds it necessary to return the 404. Any response from my go_app would look different to what I am getting now, so this is why I think the failure is earlier, in app.yaml.

Zoyd
  • 3,449
  • 1
  • 18
  • 27
Soesah
  • 155
  • 2
  • 10
  • I suppose `appengine.Main()` is a blocking call so your handler gets never registered? Try switching that line with `http.Handle("/", r)` and see if that helps. – Vincent van der Weele Mar 23 '18 at 09:34
  • Now it returns with `Internal Server Error`, but I cannot find any further information in Logging or Error Reporting. – Soesah Mar 23 '18 at 10:11
  • In your `init()` function don't you need to widen the matching pattern `http.Handle("/", r)` -> `http.Handle("/*", r)`? Is a request to `/` working? – Dan Cornilescu Mar 23 '18 at 14:23
  • That's worth a shot, but `/` is also not working at the moment. Let me give `/*` a try. ... Ah, at least we're back to 404 not found now, instead of internal server error. I appreciate any and all comments like this. I'm a little at my wits end trying to find out why my app is not working on AppEngine. Thanks – Soesah Mar 23 '18 at 18:55
  • 1
    I finally traced this back to middleware code running into a as yet unknown error – Soesah Jun 24 '18 at 17:52

0 Answers0