Many Velo modules, including universal modules such as wix-価格設定プラン.v2
and backend modules such as wix-メディアバックエンド
, include events that are triggered when the required conditions are met.
例を挙げよう:
onFileUploaded
, which fires when a file has been uploaded to the Media ManageronInvoicePaid
, which fires when an invoice is paid.Unlike the frontend, where event handlers are defined in the page code, for backend events, handlers are defined in the events.js
backend file.
Add the events.js
file as follows:
Local IDE:
Create an events.js
file in your site repo's src/backend
folder in your local IDE with Git integration.
Wix IDE (only available for Wix Studio):
Create an events.js
file in the src/backend
folder in the Wix IDE.
To define an event handler in the events.js
file, export a function with the name of the Wix module and the name of the event, separated by an underscore.
For example, to handle the onInvoicePaid
event from wix-billing-バックエンド
, declare the following function in events.js:
1
To handle the onFileUploaded
event from wix-メディアバックエンド
declare:
1
If you have any doubt about how to name the function, there is always sample code in the Velo Reference Docs to show you how to do it.
注釈
events.js
.詳しくは モジュール・エクスポート構文.Backend events are only triggered for published sites and will not work in preview mode. To test an event handler in preview mode, use functional testing. Functional testing saves you time and effort when building your own system for triggering and testing your backend functions, by allowing you to quickly test backend functions directly in the code editor.
For step-by-step instructions on how to test your backend code, see Functional Testing in the Backend.
Velo packages are code libraries built with Velo that allow you to add specific functionality to your site, saving you the time you would have spent coding the functionality on your own.
Some Velo packages include backend events, which are contained in their own events.js
files. So if you add a Velo package that includes backend events, you might end up with additional events.js
files in other locations.