Class: WSSite

WSSite

Provides methods and properties for creating a new website


Members


debugPages :Array.<string>

List of pages that will be displayed in a tab in the Console pane of the WATdebug web page.

Type:
  • Array.<string>
Since:
  • 1.3 (WAT 2.4)

<readonly> directory :string

Gets the directory name used for this app by the web server. The app is available at http://[ip addr of device]/app/[directory]/

Type:
  • string
Since:
  • 0.1 (WAT 2.0)

statusPages :Array.<string>

List of pages that will be displayed in a panel on the "Main" tab of the device administration web page.

Type:
  • Array.<string>
Since:
  • 1.0 (WAT 2.2)
Example
site.setFileContents('status/index.html', '<html><body>Status</body></html>');
site.statusPages = ['status/index.html'];

Methods


removeFile(path)

Remove a file from the web server at the specified path

Parameters:
Name Type Description
path string

The file path relative to the temporary directory

Since:
  • 0.1 (WAT 2.0)
Returns:

Indicates if the remove was successful

Type
bool

setFileContents(path, contents)

Add a file to the web server at the specified path

The contents of the file may be specified as a string or a Uint8Array. The string form is useful when the file is being generated or manipulated by the script. The Uint8Array form is useful when binary files are read from a server and used in the site. If strings are used for binary files, it is possible that the file could change when passed through the string codecs.

Parameters:
Name Type Description
path string

The file path relative to the temporary directory

contents string | Uint8Array

The file contents

Since:
  • 0.1 (WAT 2.0)
Returns:

Indicates if the add was successful

Type
bool
Examples
var ws = $wat.load('ws')[0];
var site = ws.createSite('siteName');
site.setFileContents('index.html', '<html><body><h1>The Site</h1></body></html>');
var ws = $wat.load('ws')[0];
var site = ws.createSite('siteName');
var req = XMLHttpRequest();
req.responseType = 'arraybuffer';
req.onreadstatechange = function() {
  if (this.readyState === this.DONE && this.status === 200) {
    site.setFileContents('image/logo.png', new Uint8Array(this.response));
  }
};
req.open('GET', 'image/logo.png');
req.send();