wixWindow.viewMode in the backend

How can I find out, in the backend, if the code is running on Preview or Site mode?!
Importing wix-window in the backend raises errors.
Thank you

https://www.wix.com/code/home/forum/wix-tips-and-updates/you-can-log-console-messages-in-your-backend-code

https://support.wix.com/en/article/wix-code-testing-and-debugging-your-code

I don’t think this helps since the code needs to do different things depending on where it’s running on.
I don’t want to comment/uncomment code every time I am running preview because I am just testing something.
For example:
if (wixWindow.viewMode === “Preview”)
call_external_api_TEST_MODE
else
call_external_api_PRODUCTION_MODE

However, I can’t do this in the backend js files. So, again, how do I programatically know in which environment the code is running on?
Thank you

The wixWindow API can’t be used in the backend. I guess if you really need it, you could call a backend function from the frontend that sets a flag indicating the viewMode.

What exactly are you trying to accomplish? Why does the backend code need to know if it’s running in preview/live?

Another example: myDataset_afterInsert needs to call a partner URL to generate an invoice. How does it know if it should call de dev API vs prod API. I don’t think parameters can be passed to the data hooks…

@alanrech When I test payment processing, I manually set the appropriate security keys (test or live).

I guess you could save the preview/live mode, as well as the payment processor interface information in a payment configuration collection and then retrieve the appropriate URL/key/login depending on the setting of the view-mode data collection item. I don’t think I would choose to do this myself.

There might be other ways, but I think I’m having a slow brain day.

@yisrael-wix was trying to avoid that but it seems to be the only option at the moment. How about thru the URL? Anyway that can be accesses? I suppose preview backend code runs in one place and live runs on another?
thank you