What your codebase needs
Every Custom App is made up of four parts:
The backend is the only part that holds your secrets. Ideally, the portal UI should never talks to Blnk directly; it should always go through your backend.
Set up app routes
Your app needs routes that Cloud can call to install, uninstall, and launch your app. You can name the routes however you want. The important thing is that each route exists and returns a response.For our demo Stripe Sync app, we’ll use Express to set up the routes:
routes.ts
Store app install data
When a user installs your app, Blnk Cloud sends installation details to your callback route. Your app needs a persistent place to store that data because it will need it later when the app is launched or when it makes API calls.Note: You can use any database you want. For our Stripe Sync example, we’ll go with a simple SQLite instance.
Security and best practices
Custom Apps receive scoped access to a Cloud instance during installation. Design your app so that access is stored safely, used only on the server, and checked before every action.-
Keep the API keys on the server:Theapi_keyfrom the install payload should only be used by your backend. Do not expose it in browser code, local storage, cookies, portal URLs, client-side responses, or logs. - Let your backend call Cloud: When the app portal needs data, it should not make requests to Blnk directly. Instead, it should call your backend first, then your backend speaks to Blnk.
-
Encrypt API keys at rest: Store the full
api_keyencrypted. You can storeapi_key_prefixin plain text because it only helps identify the key. Do not use the prefix to authenticate requests. -
Use short-lived portal sessions:When Cloud launches your app, return a freshportal_url. Do not return a permanent URL that always opens the app. If a session expires, ask the user to launch the app again from Cloud. -
Sign portal sessions: Use a
SESSION_SECRETto sign portal sessions. -
Check permissions before actions:Storegranted_permissionsfrom the install payload. Before your app performs an action, check that the required permission was granted. For example, an app with onlydata:readshould not perform write actions. -
Validate the install before launch:Before creating a portal session, confirm that the install exists, is active, and matches theinstalled_app_id,app_id, andinstance_idin the portal request.
Run the example Stripe Sync app
Reference Stripe sync implementation.