Skip to content

dimitrov-d/cloud-function-template

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Running Node.js scripts on Apillon Cloud Functions

The provided TypeScript code snippet is a template for deploying a script to the Acurast network through Apillon. This script is designed to establish a WebSocket connection to Acurast's decentralized network, which is essential for enabling communication between your script and the Acurast processors. Here's a breakdown of how this template works and how it fits into the deployment process:

Code Explanation

declare const _STD_: any;

_STD_.ws.open(
  [
    "wss://websocket-proxy-1.prod.gke.acurast.com/",
    "wss://websocket-proxy-2.prod.gke.acurast.com/",
  ],
  () => {
    // Success callback: Code to execute when the WebSocket connection is successfully opened
  },
  (error) => {
    // Error callback: Code to handle any errors that occur while opening the WebSocket connection
  }
);

This template and deployment process allow you to leverage Acurast's decentralized infrastructure for running your Node.js scripts, ensuring they are accessible and callable through the Apillon gateway. For more detailed runtime environment documentation, you can refer to the Acurast Developer Docs.

  • _STD_ Object: This is a special object provided by the Acurast runtime environment. It exposes various functionalities, including WebSocket operations, environment variable access, and more.

  • WebSocket Connection: The ws.open method is used to establish a connection to the Acurast network. The URLs provided are endpoints for the WebSocket proxies that facilitate communication with the network.

  • Callbacks: The code includes placeholders for success and error callbacks. You can define what actions to take when the connection is successfully established or if an error occurs.

Deployment Process

  1. Edit the Script: You can modify the index.ts file and add additional files or folders as needed for your application logic.

  2. Environment Variables: Access environment variables using _STD_.env["APILLON_API_KEY"]. This is crucial for securely managing sensitive information like API keys.

  3. Build the Script:

    • Run npm run i to install dependencies.
    • Run npm run build to compile the TypeScript code into a JavaScript bundle (index.bundle.js).
  4. Deploy the Script:

  5. Obtain Execution Endpoint: After deploying, wait a few minutes. You will obtain the callable endpoint to execute the job on the Apillon dashboard.

About

Template code for deploying an Apillon Cloud Function

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published