-
Notifications
You must be signed in to change notification settings - Fork 115
Inconsistent behaviour for parsing path and path params #46
Comments
I don't understand the "route" that you're referring to. How is it defined? Can you post your function code? |
So, I'm sorry, this was just my local testing and the names are stupid. I am actually writing go and converting to js (does not really matter in this case), let me explain by showing the source: //EntryPoint is the main handler and entrypoint for the google cloud function
func EntryPoint(req, res *js.Object) {
r := router.New(rootHandler)
r.Handle(http.MethodGet, "/hello/:ergegr", helloHandler)
r.Handle(http.MethodPost, "/site", websiteHandler)
//r.Handle(http.MethodGet, "/bq", helloBigQuery)
r.Serve(express.NewResponse(res), express.NewRequest(req))
}
func main() {
if googleCloudFunctionName == "" {
googleCloudFunctionName = "helloGO"
}
js.Module.Get("exports").Set(googleCloudFunctionName, EntryPoint)
} So, the google cloud function executor in the cloud passes on the the path (meaning the part of the path that comes after While the google cloud emulator gives me Sorry for confusing with my testing code. As stated, even though I'm doing this in Go for testing, the principle is the same, the path part is not handled the same way. |
I think the simplest example of the inconsistency can be reproduced by creating a http function with this signature: exports.helloWorld = function helloWorld (req, res) {
res.send(req.path);
}; |
If this function is deployed to the emulator vs the cloud, you will get different paths back. For my case, where I might want to use this path for something, e.g. my internal routing it breaks in the emulator. |
So, as I see it, please disregard my first two comments. They just confuse more than explain or clarify. The real consise issue is really summarized in my two above posts. |
Oh, I think I see what you mean @MartinSahlen If you deploy helloWorld to production and hit If in the emulator if you hit Is this what you're reporting? |
Okay, I can now reproduce the issue. I'm working on a fix. |
thanks! and yes @jamesdaniels that is exactly what I was trying to say. Can't believe it took that many posts to say 😂 |
Fixed in 1.0.0-alpha.5 |
@jmdobry This issue is still not resolved, I'm sorry, it's probably due to my bad explaining. The emulator and production environment still gives different paths. The emulator gives exports.helloWorld = function helloWorld (req, res) {
res.send(req.path);
}; The emulator needs to "chop off" the function name from the path before forwarding it to the handler cloud function. |
Ah I see, will fix. |
Description
The emulator does not parse the path and path params. I am implementing a simple routing mechanism that relies on getting the path minus the function name. I have looked somewhat in the emulator source and it seems that somewhere around here, the path is not forwarded to the cloud function handler: https://github.com/GoogleCloudPlatform/cloud-functions-emulator/blob/master/src/supervisor/index.js#L122
NB: query params seems to work as expected.
Steps to reproduce
I have created a function called helloGO that has a route called hello/:ergegr, that is a route with prefix path
hello
and path paramergegr
. It should return a request object that has aparams
key containing an object with a keyergegr
and a list of the params as key.See screenshot of 1):
![screen shot 2017-02-28 at 14 22 18](https://cloud.githubusercontent.com/assets/4218596/23407068/636be1ec-fdc2-11e6-9d65-0f074d04d733.png)
See screenshot of 2):
![screen shot 2017-02-28 at 14 21 16](https://cloud.githubusercontent.com/assets/4218596/23407072/6654853a-fdc2-11e6-8464-9ebd9d1228a2.png)
I dont know if this violates the intention of cloud functions but I bet at least some would agree that being able to let an endpoint / microservice handle at least some cases in in idiomatic way would be great. By idiomatic I mean paths, not having to construct huge query structures.
Thanks!
The text was updated successfully, but these errors were encountered: