Skip to content

Commit 02c4c41

Browse files
committed
Update
1 parent 2e031e3 commit 02c4c41

File tree

4 files changed

+642
-576
lines changed

4 files changed

+642
-576
lines changed

assets/operate/spa.png

36.8 KB
Loading
Loading

docs/operate/control/single-page-apps.md

Lines changed: 53 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,16 @@ linkTitle: "Create a custom web interface"
44
weight: 11
55
no_list: true
66
type: docs
7-
description: "Create and deploy single page applications on the Viam platform."
7+
description: "Create and deploy custom web interfaces for your machines as single-page applications without managing hosting and authentication."
88
---
99

10-
- Deploy front-end apps
11-
-
12-
13-
you can have multiple HTML files
14-
files have to all be deployed
15-
16-
With single page apps you can create and deploy custom web interfaces for your machines that use a single HTML page.
17-
Single page apps are accessible from a dedicated URL (`appname_publicnamespace.viamapplications.com`) and hosting and authentication is handled for you.
18-
19-
google SPA and include what exactly that means
10+
Create and deploy custom web interfaces for your machines as single-page applications without managing hosting and authentication.
11+
Once deployed, apps are accessible from a dedicated URL (`appname_publicnamespace.viamapplications.com`) and hosting and authentication is handled for you.
2012

2113
When opening an app, users log in and then select a machine they have access to.
2214
Then your app is rendered and ready for use.
2315

24-
TODO: Example GIF
16+
{{<imgproc src="/operate/spa.png" resize="400x" declaredimensions=true alt="App screen asking for the org, location, and machine." class="imgzoom shadow">}}
2517

2618
## Requirements
2719

@@ -41,11 +33,25 @@ Then authenticate your CLI session with Viam using one of the following options:
4133
{{< table >}}
4234
{{% tablestep number=1 %}}
4335

44-
**Build your single page application** using your preferred framework like React, Vue, Angular, or others.
45-
Your application should be built and ready for deployment, with all assets compiled into a distributable format.
36+
**Build your application** using your preferred framework like React, Vue, Angular, or others.
37+
While you're developing use any machine's credentials.
38+
For deploying your app you must add code to read the machine API key from your browsers local storage:
4639

47-
TODO: cover dev process
48-
TODO: how do you connect to the machine / how do you access the api key?
40+
```ts {class="line-numbers linkable-line-numbers" data-line=""}
41+
import Cookies from "js-cookie";
42+
43+
let apiKeyId = "";
44+
let apiKeySecret = "";
45+
let hostname = "";
46+
let machineId = "";
47+
48+
machineId = window.location.pathname.split("/")[2];
49+
({
50+
id: apiKeyId,
51+
key: apiKeySecret,
52+
hostname: hostname,
53+
} = JSON.parse(Cookies.get(machineId)!));
54+
```
4955

5056
{{% /tablestep %}}
5157
{{% tablestep number=2 %}}
@@ -110,44 +116,54 @@ TODO: how do you connect to the machine / how do you access the api key?
110116
The `applications` field is an array of application objects with the following properties:
111117

112118
<!-- prettier-ignore -->
113-
| Property | Type | Description |
114-
| ------------ | ------ | ------------------------------------------------------------------------------------------------- |
115-
| `name` | string | The name of your application, which will be a part of the app's URL (`name_publicnamespace.viamapplications.com`). For more information on valid names see [](/operate/reference/naming-modules). |
119+
| Property | Type | Description |
120+
| ------------ | ------ | ----------- |
121+
| `name` | string | The name of your application, which will be a part of the app's URL (`name_publicnamespace.viamapplications.com`). For more information on valid names see [](/operate/reference/naming-modules#valid-application-identifiers). |
116122
| `type` | string | The type of application (currently only `"single_machine"` is supported). |
117123
| `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: <ul><li><code>"dist/index.html"</code>: Static content rooted at the `dist` directory</li><li><code>"dist/foo.html"</code>: Static content rooted at the `dist` directory, with `foo.html` as the entry point</li><li><code>"dist/"</code>: Static content rooted at the `dist` directory (assumes `dist/index.html` exists)</li><li><code>"dist/bar/foo.html"</code>: Static content rooted at `dist/bar` with `foo.html` as the entry point</li></ul> |
118124

119125
{{% /tablestep %}}
120126
{{% tablestep number=3 %}}
127+
**Register your module** with Viam:
128+
129+
{{< tabs >}}
130+
{{% tab name="Template" %}}
121131

122-
**Package your app into a module and upload it** to the Viam Registry:
132+
```sh {class="command-line" data-prompt="$" data-output="3-10"}
133+
viam module create --name="app-name" --public-namespace="namespace"
134+
```
123135

124-
TODO: first command doesn't make sense
125-
don't use module generate
136+
{{% /tab %}}
137+
{{% tab name="Example" %}}
126138

127139
```sh {class="command-line" data-prompt="$" data-output="3-10"}
128-
viam module build local
129-
viam module upload module.tar.gz --platform=any
140+
viam module create --name="air-quality" --public-namespace="naomi"
130141
```
131142

132-
TODO: the upload command requires platform & version - is that no longer the case?
143+
{{% /tab %}}
144+
{{< /tabs >}}
145+
146+
{{% /tablestep %}}
147+
{{% tablestep number=4 %}}
133148

134-
For subsequent updates you can use:
149+
**Package your static files and your <FILE>meta.json</FILE> file and upload them** to the Viam Registry:
135150

136-
```sh {class="command-line" data-prompt="$" data-output="2-10"}
137-
viam module update
151+
```sh {class="command-line" data-prompt="$" data-output="3-10"}
152+
tar -czvf module.tar.gz <static-website-files> meta.json
153+
viam module upload module.tar.gz --platform=any --version=0.0.1
138154
```
139155

156+
For subsequent updates run these commands again with an updated version number.
157+
140158
{{% /tablestep %}}
141159
{{< /table >}}
142160

143161
## Accessing your Single Page App
144162

145-
Once your module with the application configuration is uploaded, your application will be available at:
146-
147-
TODO: any extra steps?
163+
After uploading your module with the application configuration, your application will be available at:
148164

149165
```
150-
https://your-app-name.your-public-namespace.viamapps.com
166+
https://your-app-name_your-public-namespace.viamapplications.com
151167
```
152168

153169
Users will be prompted to authenticate with their Viam credentials before accessing your application:
@@ -158,11 +174,15 @@ Users will be prompted to authenticate with their Viam credentials before access
158174
1. User is redirected to `your-app-name_your-public-namespace.viamapplications.com/machine/{machine-id}`
159175
1. Your application is rendered with access to the selected machine
160176

177+
## Example
178+
179+
For an example see [Monitor Air Quality with a Fleet of Sensors](/tutorials/control/air-quality-fleet/).
180+
161181
## Limitations
162182

163183
- Single page apps currently only support single-machine applications
164184
- All modules with apps must have public visibility
165-
- There is no versioning or separate deploy step; the page will always render the latest version
185+
- There is no separate deploy step; the page will always render the latest version
166186
- Browsers with cookies disabled are not supported
167187

168188
## Security Considerations
@@ -171,41 +191,3 @@ Users will be prompted to authenticate with their Viam credentials before access
171191
- Avoid uploading sensitive information in your application code or assets
172192
- API keys and secrets are stored in the browser's localStorage or sessionStorage
173193
- Single page apps authenticate users with FusionAuth
174-
175-
## Example
176-
177-
Here's a complete example of creating and uploading a simple React application as a Viam Single Page App:
178-
179-
```bash
180-
# Create a new React app
181-
npx create-react-app my-viam-app
182-
cd my-viam-app
183-
184-
# Build the app
185-
npm run build
186-
187-
# Create a module with the app
188-
viam module create --name my-viam-app --public-namespace your-namespace
189-
190-
# Edit meta.json to add the application configuration
191-
# Add the following to meta.json:
192-
# "visibility": "public",
193-
# "applications": [
194-
# {
195-
# "name": "my-app",
196-
# "type": "web",
197-
# "entrypoint": "build/index.html"
198-
# }
199-
# ]
200-
201-
# Copy the build directory to the module directory
202-
cp -r build/ path/to/module/
203-
204-
# Build and upload the module
205-
viam module build local
206-
viam module upload module.tar.gz
207-
```
208-
209-
After the module is approved, your application will be available at `https://my-app.your-public-namespace.viamapps.com`.
210-
211-
https://github.com/bashar-515/sample-app

0 commit comments

Comments
 (0)