Debugging backend

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?

1 Like

Hi,

calling console logs in http-functions is useless since the code is always executed on the server side.
This is unlike backend functions that are called from the front end.

To help with debugging you can create a collection that stores the JSON request/response

If the insert function fails to insert check the collection permissions

Hi,

We are in the final stage of providing you all the ability to better view all backend logs. We will update you soon.

1 Like

Thanks for that. I managed to get wixData working (stupid typo in my JS code, duh!) so have been debugging to a log file and made progress that way. I understand that server side logging to the client isn’t straightforward and was a bit surprised when the documentation seemed to suggest that it was happening.

Is there backend logs to view now?

4 Likes

bump
Also interested. Thanks

Check out these articles and video to learn how to use the Site Monitoring tool

Corvid: About Site Monitoring
Corvid: Viewing Live Site Events
Corvid: Connecting Site Events to a Monitoring Tool
Corvid: Generating a Site Monitoring Event to Debug Your Site

Corvid by Wix | How to Use the Site Monitoring Tool to Track Events and Errors @ Youtube

1 Like