Skip to content

Commit

Permalink
Updated documentation to match server revisions
Browse files Browse the repository at this point in the history
  • Loading branch information
sebjf committed Jan 10, 2024
1 parent 9fc9e99 commit 7ce5673
Show file tree
Hide file tree
Showing 3 changed files with 98 additions and 9 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 3 additions & 3 deletions Documentation/docs/nexus.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ The UCL VECG hosts multiple instances of the rendezvous server on nexus.cs.ucl.a

The checkouts are in `/home/node` and follow the format `ubiq-[branch name]`.

Currently `ubiq-master` is running on `8004`. This is the primary, public server.
Currently `ubiq-master` is running on `8010`. This is the primary, public server.

It is expected and encouraged that feature branches are created, run on nexus temporarily for development, then removed when no longer needed.

Expand Down Expand Up @@ -46,7 +46,7 @@ The `--depth 1` command downloads only the `HEAD`, which is all that is needed t
After cloning, navigate to `~/ubiq-[branch name]/Node/` and issue the commands:

1. `npm install`
2. `pm2 start app.js --name "ubiq-[branch name]"`
2. `pm2 start npm -- name "ubiq-[branch name]" -- start`

The first installs the nodejs dependencies and the second creates the pm2 job with a unique name to identify the instance.

Expand All @@ -69,7 +69,7 @@ The `-n` argument shows the port numbers, rather than showing the names of typic
To add a new rule give the commands,

```
sudo iptables -I INPUT 5 -p tcp --dport 8004 -j ACCEPT
sudo iptables -I INPUT 5 -p tcp --dport 8010 -j ACCEPT
sudo service iptables save
```

Expand Down
101 changes: 95 additions & 6 deletions Documentation/docs/serversetup.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,104 @@
# Setting up the server
# Quick Start

The server code is included in the Ubiq repository.
The server code is included in the Ubiq repository in the `Node` directory.

After checking out the code, run
After checking out the code, run,

```
npm install
```

in the `Node` directory. The server can then be started.
in the `Node` directory. The server can then be started with,

```
node app.js
```
npm start
```

This will start a server with the default TCP port - the same one running on Nexus - that Unity can connect to. Continue below if you also need to support Browser Clients.

# Advanced

## Supporting Secure WebSockets

If you are intending to create Browser Clients with Ubiq's JavaScript library, you will need to support Secure WebSockets.

This is done by providing a certificate for the server.

The quickest way to do this is to create a self-signed certificate using, e.g. OpenSSL. In the `Node` directory, give the command,

```
openssl req -nodes -new -x509 -keyout key.pem -out cert.pem
```

If successful, starting the server will look something like:

```
Added RoomServer port 8009
Added RoomServer port 8010
Added status server on port 8011
```

Self-signed certificates are unlikely to be accepted by default on most browsers. You will need to visit,

```
https://localhost:8010
```

And agree to proceed, before that browser will establish Ubiq connections.

![image](images/64a4c60f-42ec-4ecc-91fd-e02d90bcbd55.png)

## Using VSCode

If you would like to run the server in VSCode, open the `Node` Folder in VSCode, and create the following launch configuration,

```
{
"type": "pwa-node",
"request": "launch",
"name": "Launch Server",
"skipFiles": [
"<node_internals>/**"
],
"env": {"NODE_OPTIONS": "--loader ts-node/esm"},
"program": "${workspaceFolder}\\app.ts",
"console": "integratedTerminal"
}
```

## Status Module API Keys

If you want to limit access to the sensitive status module pages/APIs, you need to specify one or more API keys, for example:

```
{
"status":{
"apikeys": ["bf692145-80b1-40da-ba53-9c9dfdf7a5a7"]
}
}
```

You can copy this snippet into a new `config\local.json` file, or add your keys into the existing empty `apikeys` member in `config\default.json`.


## Alternatives ways to start the server

The server can also be started with:

```
node --loader ts-node/esm app.ts
```

or

```
NODE_OPTIONS="--loader ts-node/esm"
node app.ts
```

This is because server project is written in [TypeScript](https://www.typescriptlang.org/) and is set up to use the Node [ESM Loaders](https://dev.to/jakobjingleheimer/custom-esm-loaders-who-what-when-where-why-how-4i1o) feature to execute TypeScript (`.ts`) files directly without transpilation.

This requires the correct loader to be specified, which is done using the `--loader` parameter, either each time Node is started, or through the `NODE_OPTIONS` environment variable. (`npm start` is simply an alias for `node --loader ts-node/esm app.ts`).



0 comments on commit 7ce5673

Please sign in to comment.