Express Routing Error when using Photon Webhooks on

I have made a photon app and put on

https://groun*** as baseURL on photon webhook, PathCreate put as GameCreate. Then I created a game using Photon which succeeded. Then in my, 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?");'/' + 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 log said:

I2015-09-17T15:09:32.151Z]does this work?
I2015-09-17T15:09:32.176Z]Express Routing Error: Cannot POST //GameCreate
Could you help me with this? Why is it said "Express Routing Error"?


  • JohnTube
    JohnTube mod
    edited September 2015
    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 from to
    - change'/' + hookName, function(req, res) to, 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.
  • 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.
  • Report:
    Hi John, I have removed the '/' and now Parse's log said
    2015-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":"","version":"HTTP/1.1","x-forwarded-for":"","x-forwarded-proto":"https","x-http-method-override":"POST"}}
    Result: Success

    I2015-09-20T09:31:00.272Z]Express Routing Error: Cannot POST /GameCreate
  • Hi @thuyquai,

    Did you modify the default 'app.js' file?
    You have a problem somewhere in that file that causes a '/GameCreate' 404 not found.
    You should have this line require('cloud/GameCreate.js').register(app); before app.listen();.
  • Hi john,
    I had that line as you suggested

    photo cloud_zpsbm27wdqo.png

    I could test with from browser. When I tried to change post to get from GameCreate.js I could also access it from browser If I remember correctly. I changed it back to post though.
  • JohnTube
    JohnTube mod
    edited September 2015
    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 change, function(req, res) back to'/' + hookName, function(req, res).

  • Hey man, you are absolutely right, it absolutely work :smile: .
    So my fault was:
    1. I put instead of and it result in the //GameCreate error.
    2. Then I change the'/' + hookName to and still the same error
    3. I then changed to which is a right move but still keep 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 this :)