So, I have read “Testing and Debugging Code with Wix Code” but reality doesn’t seem to work that way!
I have written a function in http-functions.js to handle a webhook from an external site. When I test it in preview mode, I can see from the external site that the http request is being received and a response sent back. I can vary that response by returning ok, created, notFound, etc. from the code so I know that there is nothing fundamentally wrong with the setup.
Now I need to debug in order to view the payload of the webhook, which is a Json object, and check that I am unpacking it correctly. But I never see any output from my console.log calls in the browser developer console or the wix console in preview. Putting console.log calls in the code for the home page gives exactly what I would expect, but not in http-functions.js. The wix console tells me to “open masterPage.js in Developer Tools” in order to debug. When I do that all I see is an empty onReady function, not the code I have written and want to step through.
There is another issue, that attempting to write to a database collection from within http-functions.js always fails so I’m not even able to use a log file as a fallback. In any case, writing to the database is a fundamental part of handling the webhook, so I need to get that working as well. Again, my database access code works fine when it is in the home page, so this isn’t just a coding error. And the examples in “Exposing a Site API with HTTP Functions” use effectively the same code structure as I have got, to save data records.
So what is going on?