Express Routing Error when using Photon Webhooks on Parse.com
Options
I have made a photon app and put on
https://groun***eakers.parseapp.com/ as baseURL on photon webhook, PathCreate put as GameCreate. Then I created a game using Photon which succeeded. Then in my Parse.com, I deploy the cloud code provided by Photon:
var hookName = "GameCreate"; var fail = require('cloud/util.js').fail(hookName); var ok = require('cloud/util.js').ok(hookName); var db = require('cloud/db.js'); exports.register = function(app){ console.log("does this work?"); app.post('/' + hookName, function(req, res) { console.log(hookName + ": before req.query = " + JSON.stringify(req.query)); console.log(hookName + ": before req.body = " + JSON.stringify(req.body)); var ctx = {hookName: hookName, ret: {ResultCode: 0, Mesage: ""}, res: res, fail: fail, ok: true}; console.log(hookName + ": req.query = " + JSON.stringify(req.query)); console.log(hookName + ": req.body = " + JSON.stringify(req.body));The "does this work?" is displayed but not the later console.logs. Here is what Parse.com log said:
Could you help me with this? Why is it said "Express Routing Error"?
I2015-09-17T15:09:32.151Z]does this work?
I2015-09-17T15:09:32.176Z]Express Routing Error: Cannot POST //GameCreate
0
Comments
-
Hi @thuyquai,
From the logged error it is clear that the relative path is interpreted as "//GameCreate" instead of "/GameCreate".
Please try removing one [forward] slash ('/'). You have two options:
- change the base URL fromhttps://groundbreakers.parseapp.com/
tohttps://groundbreakers.parseapp.com
.
- changeapp.post('/' + hookName, function(req, res)
toapp.post(hookName, function(req, res)
.
This is not a Photon related issue btw. A little bit of Googling does no harm. On the contrary you could learn new cool things.1 -
thanks John . I have google for a day before posting the question. i'll try as you suggested. I did try the second option though, will test the first option now. I'll report back if it works.0
-
Report:
Hi John, I have removed the '/' and now Parse's log said2015-09-20T09:30:59.894Z]v59 Ran custom endpoint with:
Input: {"method":"POST","url":"/GameCreate","headers":{"accept":"application/json","content-length":"364","content-type":"application/json","host":"groundbreakers.parseapp.com","version":"HTTP/1.1","x-forwarded-for":"10.252.5.60","x-forwarded-proto":"https","x-http-method-override":"POST"}}
Result: Success
I2015-09-20T09:31:00.272Z]Express Routing Error: Cannot POST /GameCreate0 -
-
You have a problem with 'GameCreate.js' file. Please use the original one from the github repo.
I tried all other webhooks and they work fine.
Maybe you forgot to changeapp.post(hookName, function(req, res)
back toapp.post('/' + hookName, function(req, res)
.
Hamza1 -
Hey man, you are absolutely right, it absolutely work .
So my fault was:
1. I put https://groundbreakers.parseapp.com/ instead of https://groundbreakers.parseapp.com and it result in the //GameCreate error.
2. Then I change the app.post('/' + hookName to app.post(hookName and still the same error
3. I then changed https://groundbreakers.parseapp.com/ to https://groundbreakers.parseapp.com which is a right move but still keep app.post(hookName thus result in the Can not post /GameCreate error.
4. After that I follow your final tip and revert the GameCreate file back to it's origional state and it works!!!
Thanks for your help, I really appreciated this0