{"id":23246471,"url":"https://github.com/openware/nodelogic","last_synced_at":"2025-07-25T13:08:06.421Z","repository":{"id":42991839,"uuid":"197375389","full_name":"openware/nodelogic","owner":"openware","description":"Example Node.js application to extend the OpenDAX stack","archived":false,"fork":false,"pushed_at":"2022-12-22T11:59:09.000Z","size":3315,"stargazers_count":6,"open_issues_count":8,"forks_count":11,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-07-18T14:53:52.807Z","etag":null,"topics":["barong","node-js","openware","peatio","rubykube"],"latest_commit_sha":null,"homepage":"https://www.openware.com","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/openware.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-07-17T11:22:12.000Z","updated_at":"2025-02-17T03:26:35.000Z","dependencies_parsed_at":"2023-01-30T08:15:26.851Z","dependency_job_id":null,"html_url":"https://github.com/openware/nodelogic","commit_stats":null,"previous_names":[],"tags_count":13,"template":false,"template_full_name":null,"purl":"pkg:github/openware/nodelogic","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/openware%2Fnodelogic","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/openware%2Fnodelogic/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/openware%2Fnodelogic/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/openware%2Fnodelogic/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/openware","download_url":"https://codeload.github.com/openware/nodelogic/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/openware%2Fnodelogic/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":267009996,"owners_count":24020720,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-07-25T02:00:09.625Z","response_time":70,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["barong","node-js","openware","peatio","rubykube"],"created_at":"2024-12-19T07:15:13.091Z","updated_at":"2025-07-25T13:08:06.400Z","avatar_url":"https://github.com/openware.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Node JS Applogic for the Openware stack\n\n### Start the app\nTo start up the application simply run\n`npm install`\n`npm run start`\n\n### Configuration\nAll the config is stored inside `config/config.json` file or can be defined using env variables\nTo have a correctly working app you also need to configure management API in barong:\n\n* Open `management_api.yml`\n* Add applogic public key to the keychains\n```yaml\nkeychain:\n  nodelogic:\n    algorithm: RS256\n    value: base64_encoded_public_key\n```\n* Add required scopes for your application.\n```yaml\nscopes:\n  read_user:\n    permitted_signers: ['nodelogic']\n    mandatory_signers: ['nodelogic']\n```\nNow you can bring up the stack and test nodelogic application\n\n### Testing\nTo verify that your Applogic is working with a Microkube installation you need to first create a session for user\n\nYou can do so by using `http` command line tool\nTo install *http* cli follow this [guide](https://httpie.org/#installation)\n\n`http --session=new POST http://www.app.local/api/v2/barong/identity/sessions email='admin@barong.io' password='0lDHd9ufs9t@'`\n\nAfter that you can check if applogic endpoint is working\n\n`http --session=new POST http://www.app.local/api/v2/applogic/users/get email='john@barong.io'`\n\nThis endpoint returns a user taken from barong, the communication between applogic and barong is done using management api.\n\n## How to develop your own Nodelogic?\n\nBefore we create the app we need to understand how the authorization and sharing session works.\n\nAuthorization flow diagram is presented below:\n\n![Authorization Flow Diagram](docs/images/auth-flow.png)On a successful use login, a cookie will be set. After that thi\n\nAfter JWT is decoded, the app has access to this object.\n\n```\n{ iat: 1565687278,\n  exp: 1565693278,\n  sub: 'session',\n  iss: 'barong',\n  aud: [ 'peatio', 'barong' ],\n  jti: '1111111111',\n  uid: 'ID123123123',\n  email: 'admin@barong.io',\n  role: 'admin',\n  level: 3,\n  state: 'active',\n  referral_id: null }\n```\n\n**An already working example can be found [here](https://github.com/openware/nodelogic)**\n\nFor this tutorial we're going to extend rubykube api with another component written in Node js. This is a simple compon\n\n1. **Create a new Express app:**\n\n   ```zsh\n   ➜  mkdir my_app\n   ➜  cd my_app\n   ➜  npm init --yes\n   ➜  npm i express node-auth-barong\n   ➜  touch app.js\n   ```\n\n2. **Create an example Server:**\n\n   Simple server file `app.js`\n\n```js\nconst express = require('express')\nconst barongJwt = require('node-auth-barong')\nconst app = express()\nconst port = 3000\n\napp.use(barongJwt({barongJwtPublicKey: Buffer.from(process.env.BARONG_JWT_PUBLIC_KEY.trim(), 'base64').toString('utf-8'\n\napp.get('/api/user/me', (req, res) =\u003e res.send(req.session.email))\n\napp.listen(port, () =\u003e console.log(`Example app listening on port ${port}!`))\n\n```\n\n3. **Integrate it in microkube and test**\n\n* Create a dockerfile for our app and build image\n\n  ``````dockerfile\n  FROM node:11.14.0-stretch\n\n  ARG UID=1000\n  ARG GID=1000\n\n  ENV APP_HOME=/home/app\n\n  # Create group \"app\" and user \"app\".\n  RUN useradd --system --create-home --home ${APP_HOME} --shell /sbin/nologin --no-log-init app\n\n  WORKDIR $APP_HOME\n  USER app\n\n  COPY --chown=app:app package.json package-lock.json $APP_HOME/\n\n  # Install dependencies\n  RUN npm i\n\n  # Copy the main application.\n  COPY --chown=app:app . $APP_HOME\n\n  EXPOSE 3000\n\n  CMD [\"node\",\"app.js\"]\n  ``````\n\n   `docker build -t myapp:test .`\n\n* Create a compose entry in microkube\n\n  Let's change our directory to microkube\n\n  ```\n  cd ~/\n  git clone git@github.com:rubykube/microkube.git\n  cd microkube\n  ```\n\n  Append the following block to `templates/compose/app.yaml.erb` , by doing so we've created a new service called **mya\n\n  ```yaml\n    myapp:\n      image: \"\u003c%= @config['images']['myapp'] %\u003e\"\n      env_file:\n        - ../config/myapp.env\n      ports:\n        - \"3000:3000\"\n  ```\n\n* Create a env file for our app\n\n  Let's create a file `templates/config/myapp.env.erb` , stay aware of the name, because we reference it in compose fil\n\n  ```BARONG_JWT_PUBLIC_KEY=\u003c%= @jwt_public_key %\u003e```\n\n  This is the only line we need.\n\n* Reference our app docker image in microkube/app.yml\n\n  `````yaml\n  app:\n    name: \"Microkube\"\n    domain: \"app.local\"\n    subdomain: \"www\"\n  ssl:\n    enabled: true\n    email: \"support@example.com\"\n  images:\n    peatio: rubykube/peatio:2.0.34\n    barong: rubykube/barong:2.0.51\n    frontend: rubykube/mikroapp:0.1.5\n    myapp: myapp:test # here we specify the tag we have build our image with\n    tower: rubykube/tower:0.1.8\n    postmaster: quay.io/openware/postmaster:0.0.3\n    arke: rubykube/arke:0.1.5\n  vendor:\n    frontend: https://github.com/rubykube/mikroapp.git\n  storage:\n    provider: \"Google\"\n    bucketName: \"microkube-barong-docs-bucket\"\n    accessKey: \"**********\"\n    secretKey: \"**********\"\n  terraform:\n    credentials: \"~/safe/microkube.json\"\n    project: \"example-microkube\"\n    region: \"europe-west4\"\n    zone: \"europe-west4-a\"\n    instance_name: \"microkube-cloud\"\n    machine_type: \"n1-standard-4\"\n    image: \"debian-cloud/debian-9\"\n  twilio:\n    phone_number: \"+15005550000\"\n    account_sid: \"changeme\"\n    auth_token: \"changeme\"\n  sendgrid_api_key: changeme\n  arke:\n    strategy:\n      type: 'copy'\n      pair: 'ETHUSD'\n      target:\n        driver: rubykube\n        host: 'http://www.app.local'\n        name: John\n        key: changeme\n        secret: changeme\n      sources:\n        - driver: bitfinex\n          name: Joe\n          key: changeme\n          secret: changeme\n  `````\n\n* Add our application to envoy configuration\n\n  Open `templates/config/gateway/envoy.yml.erb`\n\n  ```yaml\n  static_resources:\n    listeners:\n    - address:\n        socket_address:\n          address: 0.0.0.0\n          port_value: 8099\n      filter_chains:\n      - filters:\n        - name: envoy.http_connection_manager\n          config:\n            codec_type: auto\n            stat_prefix: ingress_http\n            route_config:\n              name: local_route\n              virtual_hosts:\n              - name: backend\n                domains:\n                - \"*\"\n                routes:\n                - match:\n                    prefix: \"/api/v2/barong\"\n                  route:\n                    cluster: barong\n                    prefix_rewrite: \"/api/v2/\"\n                - match:\n                    prefix: \"/api/v2/peatio\"\n                  route:\n                    cluster: peatio\n                    prefix_rewrite: \"/api/v2/\"\n                - match:      # add another match for our service\n                \t  prefix: \"/api/myapp\" # this path on front\n                \troute:\n                \t  cluster: myapp # we will define this cluster below\n                \t  prefix_rewrite: \"/api\" # will rewrite to this path on our service\n                - match:\n                    prefix: \"/admin\"\n                  route:\n                    cluster: peatio\n                - match:\n                    prefix: \"/assets/\"\n                  route:\n                    cluster: peatio\n                - match:\n                    prefix: \"/api/v2/ranger/public\"\n                  route:\n                    cluster: ranger\n                    prefix_rewrite: \"/\"\n                    upgrade_configs:\n                      upgrade_type: \"websocket\"\n                - match:\n                    prefix: \"/api/v2/ranger/private\"\n                  route:\n                    cluster: ranger\n                    prefix_rewrite: \"/\"\n                    upgrade_configs:\n                      upgrade_type: \"websocket\"\n            http_filters:\n            - name: envoy.ext_authz\n              config:\n                http_service:\n                  allowed_authorization_headers:\n                  - location\n                  - set-cookie\n                  - authorization\n                  - proxy-authenticate\n                  - www-authenticate\n                  allowed_request_headers:\n                  - user-agent\n                  - cookie\n                  - x-forwarded-proto\n                  - authorization\n                  - proxy-authorization\n                  - x-forwarded-host\n                  - x-forwarded-for\n                  - from\n                  path_prefix: \"/api/v2/auth\"\n                  server_uri:\n                    cluster: barong\n                    timeout: 1.000s\n                    uri: http://barong:8001\n            - name: envoy.router\n              config: {}\n    clusters:   # here is the set of available services to route to\n    - name: barong\n      connect_timeout: 0.25s\n      type: strict_dns\n      lb_policy: round_robin\n      hosts:\n      - socket_address:\n          address: barong\n          port_value: 8001\n    - name: peatio\n      connect_timeout: 0.25s\n      type: strict_dns\n      lb_policy: round_robin\n      hosts:\n      - socket_address:\n          address: peatio\n          port_value: 8000\n    - name: myapp\n      connect_timeout: 0.25s\n      type: strict_dns\n      lb_policy: round_robin\n      hosts:\n      - socket_address:\n          address: myapp    # here we specify docker-compose service name because they are on the same network\n          port_value: 3000 # the port we've defined in docker-compose\n    - name: ranger\n      connect_timeout: 0.25s\n      type: strict_dns\n      lb_policy: round_robin\n      hosts:\n      - socket_address:\n          address: ranger\n          port_value: 8080\n  admin:\n    access_log_path: \"/dev/null\"\n    address:\n      socket_address:\n        address: 0.0.0.0\n        port_value: 9099\n  ```\n\n* Run the application\n\n  We need to bring up all the stack to test our app:\n\n  `rake service:all`\n\n  Now, let's deploy our app:\n\n  `docker-compose up -Vd myapp`\n\n* Test deployed application\n\n  For easier testing let's install [httpie](https://httpie.org)\n\n  After installing httpie we're going to create a session for a user and test our application\n\n  * Add an entry to `/etc/hosts`\n\n    Add this line to the file, to be able to access our application on one hostname\n\n    ```\n    0.0.0.0 www.app.local\n    ```\n\n  * Create a session\n\n    ```json\n    http --session=test POST http://www.app.local/api/v2/barong/identity/sessions email='admin@barong.io' password='0lD\n    HTTP/1.1 200 OK\n    Cache-Control: max-age=0, private, must-revalidate\n    Content-Length: 102\n    Content-Type: application/json\n    Date: Tue, 13 Aug 2019 10:52:54 GMT\n    Etag: W/\"03851ef25f9cd7e9372e07e9fa955cc1\"\n    Server: envoy\n    Set-Cookie: _session_id=j7aR4UMJXiCzpUIjk7VO9uZLICX%2FbWl4dB8yZRrQma9TOyquNseMXpL%2FsRvo4fR2Dth40%2BuIyku5%2F9C8DKd\n    Set-Cookie: _barong_session=7ikfYh7o8gmGGqETgBAx7Nfkn0547d9bRKNkmiwz%2B4JiBh3yxT8AsDoAIZwHf3vRd%2FOp5ZCEEfcLRUnw1ig\n    Vary: Origin\n    X-Envoy-Upstream-Service-Time: 326\n    X-Request-Id: e20b879f-3c28-4a2e-8cb2-061aa4e98acc\n    X-Runtime: 0.325521\n\n    {\n        \"email\": \"admin@barong.io\",\n        \"level\": 3,\n        \"otp\": false,\n        \"role\": \"admin\",\n        \"state\": \"active\",\n        \"uid\": \"ID88613C9575\"\n    }\n    ```\n\n  * Test our application\n\n    ```json\n    http --session=test GET http://www.app.local/api/myapp/user/me\n    HTTP/1.1 200 OK\n    Content-Length: 15\n    Content-Type: text/html; charset=utf-8\n    Date: Tue, 13 Aug 2019 10:53:38 GMT\n    Etag: W/\"f-LjSPa0aKBpanEuP1qo3W6qAFJeY\"\n    Server: envoy\n    X-Envoy-Upstream-Service-Time: 12\n    X-Powered-By: Express\n\n    admin@barong.io\n    ```\n\n#### CONGRATULATIONS! You've successfully developed and deployed your custom component for the Openware stack. Now sky is your only limit.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fopenware%2Fnodelogic","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fopenware%2Fnodelogic","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fopenware%2Fnodelogic/lists"}