bridge-local-dev/README.md
Martin Donnelly 78a95206a3 init
2018-06-24 21:13:31 +01:00

89 lines
4.4 KiB
Markdown

This repo contains tools to help run a local version of node_server.
This is ideal for development and local testing without interfering with
any of the servers.
## To Use
1. For mongo and minio, install [Virtual Box](https://www.virtualbox.org/).
2. For mongo and minio, install [Vagrant](https://www.vagrantup.com/).
3. Follow the steps in `mongodb\README.md` to install and run a local mongodb
4. Follow the steps in `nginx\README.md` to install and run a local nginx proxy
5. Follow the steps in `minio\README.md` to install and run a local minio serverr
6. Set the environment for the node server appropriately for the local setup (see below)
7. Run your local dev server as (see below)
## Running local dev server
To run a local debug server you need to (after installing the support tools as above):
1. Install node.js 8.x
2. Clone the https://bitbucket.org/comcarde/bridge-node-server repo
3. Copy the compiled email templates into `node_server/email_templates/` from either
* Get them from from Jenkins http://10.0.10.240:8080/job/Emails%20Build/lastSuccessfulBuild/artifact/bin/
* Build locally by checking out https://bitbucket.org/comcarde/comcarde-server-emails and `gulp compile --production` then copying bin
4. Run `npm install`
5. Set the environment variables up as described below
6. Run your server using node (e.g. through your prefered IDE)
7. Use `gulp test-watcher --cwd node_server` to run unit tests automatically on each file modification
## REQUIRED Local Debug Server environment variable
You will need to set your environment for the local debug node server to match
this local setup. All standard environment variables used in the server should
be included, but the following values should be modified from the real servers.
| Setting | Value | Reason |
|--------------------|----------------------|--------|
| `loadbalancer_vip` | `localhost` | Used in `trust proxy` setting in express. Address of the nginx proxy. |
| `webAddress` | `localhost` | The expected hostname for requests, for configuring CORS for the portal, etc.|
| `mongoUser` | `mdbadmin` | As set in the mongodb VM |
| `mongoPassword` | `abc123` | As set in the mongodb VM |
| `mongoDBAddress` | `@172.16.0.20:27017` | As set in the mongodb VM |
| `mongoUseSSL` | `true` | The mongodb VM uses SSL |
| `mongoCACertBase64`| `<certpath>/mongodb.pem` | WARNING: This path is **relative to `node_server`**! Ignore the bad naming, this should point to a PEM file, not a Base64 value! The SSL is encryption only and the CA of the cert is not verified, so *any* pem file will do. The one from the MongoDB setup is a reasonable one to use for dev. Recommended location is `../../mongodb.pem` so it sits outside the git repo and doesn't have to be ignored every commit.|
| `minioEndpoint` | "172.16.0.21" | Minio local IP |
| `minioPort` | "9000" | Minio local Port |
| `minioAccessKey` | "XXXXXXXXXXXXXXXXXXXX" | See /minio/README.md |
| `minioSecretKey` | "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" | See /minio/README.md |
| `minioStorageBucket` | "dev" | Name of Minio bucket |
Other required fields will be notified at startup.
## OPTIONAL Debug Server environment
The following optional environment variables can be useful depending on what
parts of the server you are wanting to debu
| Setting | Value | Reason |
|--------------------|----------------------|--------|
| `debug` | `core:*,ComServe:*` | Defines which `debug()` statements in the code to enable. See the [debug module on NPM](https://www.npmjs.com/package/debug) for details |
## Optional Code Modifications for local dev
The following code modifications can make it easier to do local development:
### Removing HMAC checks
When using Postman or similar to simulate a device and call the commands you want
to test, it is easier to disable the HMAC checking (as HMACs are hard to calculate
in Postman).
At the top of `ComServe/auth.js` -> `checkHMAC()`, add:
```
next(null);
return;
```
to remove the checks.
### Debug the webconsole
If you are debugging the webconsole project, and it's running on http instead of
https, you need to change the CORS config or the browser will block your requests.
At the top of `swagger_api\api_cors_middleware.js` change:
`const ORIGIN_PROTOCOL = 'https';`
to:
`const ORIGIN_PROTOCOL = 'http';`