Skip to content

Latest commit

 

History

History
139 lines (97 loc) · 5.5 KB

README_dev.md

File metadata and controls

139 lines (97 loc) · 5.5 KB

Setup

  1. download and install Docker Desktop
  2. download and install Node JS
  3. Optional: install the npm package typescript globally to use the tsc command without the npx prefix
  4. Optional: install the VS Code extension Tasks
  5. Optional: restarting the Connector using the VSCode task More Tasks > Restart requires the tool socat. Make sure to install it on your system. This can be done for example using apt-get install socat on Ubuntu and brew install socat using Homebrew.
  6. run npm i

How to run

To configure the Connector for development you have to create an .env file in the .dev folder.

You can use the .env.example file as a template. The file can be named anything you want (it should be prefixed with .env), but we recommend to use .env as the name. If you want to use multiple .env files for different environments, you can postfix the file name with the environment name (e.g. .env.stage).

To run a single Connector instance, execute the following command:

docker compose -f .dev/compose.yml --env-file [path_to_your_env_file] up --build connector-1

To run two Connector instances, execute the following command:

docker compose -f .dev/compose.yml --env-file [path_to_your_env_file] up --build connector-1 connector-2

⚠️ Replace [path_to_your_env_file] with e.g. .dev/.env, depending on where your env file is located.

ℹ️ You can also use the VS Code task Run 1 or Run 2 and configure the appropriate env file to start your connector instances.

After a few seconds you should see the following output:

connector-1  | [2021-01-25T11:27:40.788] [INFO] Transport.Transport - Transportinitialized
...
connector-1  | [2021-01-25T11:27:41.241] [INFO] HttpServerModule - Listening on port 80
...
connector-1  | [2021-01-25T11:27:41.241] [INFO] Runtime - Started all modules.

You can access the Swagger UI of the Connector under http://localhost:3000/docs.

To use an local backbone, that can be started with npm run start:backbone, you can use the .env.local in the .dev folder

docker compose -f .dev/compose.yml --env-file .env.local up --build connector-1
docker compose -f .dev/compose.yml --env-file .env.local up --build connector-1 connector-2

How to debug

  1. Execute the VS Code task Compile. This task executes tsc -w (watches the code and compiles on change).
  2. Run the Connector as described in the previous chapter.
  3. To attach the debugger, switch to the VS Code "Run" view, select the Run configuration Attach to Connector 1 or Attach to Connector 2 and click the Run button.

If you're running on Linux (or wsl), every time you save a file, the server is restarted, as long as you don't cancel the Compile task.

If you're running on Windows you have to execute the Restart task after you saved a file. This is because when mounting a folder from the Windows file system into a Linux Docker container, the file system events are not being mapped properly.

How to test

Remote Backbone

Set the following environment variables:

  • NMSHD_TEST_BASEURL (the backbone baseUrl to test against)
  • NMSHD_TEST_CLIENTID (the backbone clientId for the configured baseUrl)
  • NMSHD_TEST_CLIENTSECRET (the backbone clientSecret for the configured baseUrl)

We recommend to persist these variables for example in your .bashrc / .zshrc or in the Windows environment variables.

Local Backbone

To start a local backbone, execute the following command:

npm run start:backbone

Set the following environment variables:

  • NMSHD_TEST_BASEURL to http://localhost:8090
  • NMSHD_TEST_CLIENTID to test
  • NMSHD_TEST_CLIENTSECRET to test

We recommend to persist these variables for example in your .bashrc / .zshrc or in the Windows environment variables.

Run the tests

npm run test:local

If you only want to run a single test suite you can use the following command:

npm run test:local -- testSuiteName

Run the Connector without Docker MongoDB or other Dependencies

  1. clone this repository git clone https://github.com/nmshd/connector.git
  2. change into the directory cd connector
  3. install the npm dependencies npm i
  4. build the connector npm run build
  5. create a config file (for example local.config.json)
    {
      "debug": true,
      "transportLibrary": {
          "baseUrl": "...",
          "platformClientId": "...",
          "platformClientSecret": "..."
      },
      "database": { "driver": "lokijs", "folder": "./" },
      "logging": { "categories": { "default": { "appenders": ["console"] } } },
      "infrastructure": { "httpServer": { "apiKey": "xxx", port: 8080 } },
      "modules": { "coreHttpApi": { "docs": { "enabled": true } } }
    }
    
  6. replace ... in the config with real values
  7. start the connector using CUSTOM_CONFIG_LOCATION=./local.config.json node dist/index.js

It's now possible to access the connector on port 8080. Validating this is possible by accessing http://localhost:8080/docs/swagger in the browser.

Connector SDK development

Build

  • run npm ci (this will symlink the SDK in the node_modules of the Connector)
  • run npm run build --workspaces to build the changes for the Connector and its packages

Publish

The SDK is published, when you merge the project to main while having changed the package version.