Next
Create a web app
Create and deploy a custom web interface for your machines without managing hosting and authentication.
Once deployed, your application is accessible from a dedicated URL (appname_publicnamespace.viamapplications.com
), and hosting and authentication is handled for you.
Users log into your application and select a machine they have access to. The application then renders your custom interface for interacting with the user’s machine.
You can build a custom web interface to access your machines using your preferred framework like React, Vue, Angular, or others.
When logging into a Viam application and selecting a machine to use it with, the machine’s API key is stored as a cookie. You can access the data from your browser’s cookies as follows:
import Cookies from "js-cookie";
let apiKeyId = "";
let apiKeySecret = "";
let host = "";
let machineId = "";
// Extract the machine identifier from the URL
const machineCookieKey = window.location.pathname.split("/")[2];
({
apiKey: { id: apiKeyId, key: apiKeySecret },
machineId: machineId,
hostname: host,
} = JSON.parse(Cookies.get(machineCookieKey)!));
For developing your application on localhost:
Run your web server.
Run the following command specifying the address where your app is running on localhost and a machine to test on.
The command will proxy your local app and open a browser window and navigate to http://localhost:8012/machine/<machineHostname>
for the machine provided with –machine-id.
viam login
viam module local-app-testing --app-url http://localhost:<PORT> --machine-id <MACHINE-ID>
viam login
viam module local-app-testing --app-url http://localhost:3000 --machine-id a1b2c3d4-e5f6-7890-abcd-ef1234567890
When using your deployed application, static files will be accessible at https://your-app-name_your-public-namespace.viamapplications.com/machine/<machineHostname>/
.
If your HTML file loads other files, use relative paths to ensure your files are accessible.
To deploy your application with Viam you must package it as a module and upload it using the Viam CLI.
Create a
{
"module_id": "your-namespace:your-module",
"visibility": "public",
"url": "https://github.com/your-org/your-repo",
"description": "Your module description",
"applications": [
{
"name": "your-app-name",
"type": "single_machine",
"entrypoint": "dist/index.html"
}
]
}
{
"module_id": "acme:dashboard",
"visibility": "public",
"url": "https://github.com/acme/dashboard",
"description": "An example dashboard for a fictitious company called Acme.",
"applications": [
{
"name": "dashboard",
"type": "single_machine",
"entrypoint": "dist/index.html"
}
]
}
This file specifies the contents of the module. It is required for your module.
The applications
field is an array of application objects with the following properties:
Property | Type | Description |
---|---|---|
name | string | The name of your application, which will be a part of the application’s URL (name_publicnamespace.viamapplications.com ). For more information on valid names see Valid application identifiers. |
type | string | The type of application (currently only "single_machine" is supported). |
entrypoint | string | The path to the HTML entry point for your application. The entrypoint field specifies the path to your application’s entry point. For example:
|
Register your module with Viam:
viam module create --name="app-name" --public-namespace="namespace"
viam module create --name="air-quality" --public-namespace="naomi"
Package your static files and your
tar -czvf module.tar.gz <static-website-files> meta.json
viam module upload --upload=module.tar.gz --platform=any --version=0.0.1
For subsequent updates run these commands again with an updated version number.
After uploading your module with the application configuration, your application will be available at:
https://your-app-name_your-public-namespace.viamapplications.com
Users will be prompted to authenticate with their Viam credentials before accessing your application:
your-app-name_your-public-namespace.viamapplications.com
.your-app-name_your-public-namespace.viamapplications.com/machine/<machineHostname>
.For a TypeScript example see Monitor Air Quality with a Fleet of Sensors.
For a React application that shows camera feeds for a machine, see Viam Camera Viewer.
Viam does not currently support using custom domains (for example: app.mycustomdomain.com/machine/<machineHostname>
) to serve your Viam application.
You can, however, redirect from your domain to your Viam application (app.mycustomdomain.com
-> your-app-name_your-public-namespace.viamapplications.com
).
You can configure a redirect (HTTP 301) on your web server or hosting provider from app.mycustomdomain.com/*
to your-app-name_your-public-namespace.viamapplications.com/*
.
Was this page helpful?
Glad to hear it! If you have any other feedback please let us know:
We're sorry about that. To help us improve, please tell us what we can do better:
Thank you!