view README.md @ 274:bdbc30b9f43c default tip master

Alternative authService migration approach Allows one service instance to be shared between Angular and AngularJS. Reviewed-by: jkang Review-thread: http://icedtea.classpath.org/pipermail/thermostat/2017-October/025509.html
author Andrew Azores <aazores@redhat.com>
date Thu, 26 Oct 2017 10:47:34 -0400
parents 0dc8909dd90e
children
line wrap: on
line source

# Thermostat Web-Client

AngularJS & Patternfly Application: Thermostat UI

[![Chat](https://img.shields.io/badge/chat-on%20freenode-brightgreen.svg)](https://webchat.freenode.net/?channels=#thermostat)

## Dependencies:

`Google Chrome` or `Chromium` browser with version >=58 for integration testing.

`npm`, which will pull down all other dependencies.

`keycloak.json` generated by a Keycloak server (if desired, ie, running with
`NODE_ENV=production`), placed in `src/app/components/auth/`. The file contents should
look like:

    {
        "url": "http://some.domain:PORT/auth",
        "realm": "FooRealm",
        "clientId": "BarClientId"
    }

The webserver which serves the client should expose a path `/gatewayurl`, which returns
a string representation of a JSON object like this:
`{ "gatewayUrl": "http://example.com:1234/" }`, where the URL returned points to the
root of the associated Thermostat Web-Gateway server.

## Environments

Expected values for `NODE_ENV`:

- `production` for production environments, which produces a smaller application
bundle and expects Keycloak configuration

- `testing` for test environments, ex. CI

- `development` for individual developers' machines

In `testing` and `development`, one hard-coded user exists. The username is
`test-user` and the password is `test-pass`. This is intended _only_ for
development and testing, never for deployments.

When building with `npm run build`, these values should be set via a standard
shell environment variable. When building with `s2i build`, the file `.s2i/environment`
should exist and contain ex. `NODE_ENV=production`.

## How to use

**Live-reload development:**

`npm run devserver`, then point a web browser at localhost:8080.

**One-time build:**

`npm run build` for a build with unit tests but *not* integration tests, or

`npm run verify` for a build with unit tests and integration tests. This
requires the embedded webserver and mockapi-server to be able to run and bind
on their respective ports, as described below.

**Non-live-reload web-server:**

`npm start`, then point a web browser at localhost:8080.

In this case, you may run the server on a different port than the default `8080`
by setting the environment variable `PORT` to a port number of your choosing.
The server also binds by default on `0.0.0.0`, which can be overridden with the
environment variable `HOST`.

This will also bring up the mock API endpoint server, which by default will run
on port `8888` and bind to `0.0.0.0`. These can be overridden with the
environment variables `MOCKAPI_PORT` and `MOCKAPI_HOST`.

The webserver and mockapi-server are both run as daemons. They can be stopped
using `npm stop`.

**Testing**

Unit tests are run with both `npm run build` and `npm run verify`, but
integration tests are only run on `npm run verify`.

To run unit tests separately from a build, use `npm test` for a one-shot test
suite execution, or `npm run test-watch` to monitor test files and rerun the
suite when any test file changes.

To run integration tests separately, use `npm run integration-test`. This will
require the embedded webserver to be running, using ex. `npm start`. The
integration test server requires Chromium or Google Chrome browser with major
version >= 58 to be installed on the host system.

### Development Tips

1. `npm completion` outputs a script which will enable completion for things like
`npm run <TAB><TAB>`, which will offer completions for web-client build and run
scripts. You can save this file in your home directory and source it in your
`.bashrc` for example, or put it somewhere system-wide. On Fedora, putting the
output of this command in the file `/etc/bash_completion.d/npm` will work for
system-wide completion enabling.

### Localization

String localizations are provided by `{lang}.locale.yaml` files distributed throughout
the project sources. These files are recommended (but not strictly required) to be placed
adjacent to the views which reference them. The top-level locale file adjacent to
index.html is the only one which does not use a component namespace; all other locale
files should be namespaced to match their parent component. Locale namespaces should be
named with camelCase. Localization keys should be named with UPPER_SNAKE_CASE.

New locales must be registered in the $translateProvider configuration in app.module.js.

### Source-to-Image

`s2i` can also be used to produce an application image. The expected base image
is `centos/nodejs-6-centos7`, although others may also work. The build invocation
will look like `s2i build . centos/nodejs-6-centos7 thermostat-web-client` and
running the image will look like `docker run -it --rm -p 9090:8080 thermostat-web-client`,
which will bind the application to port 9090 on the host machine.

The `PORT` and `HOST` variables outlined above may also be set in `.s2i/environment`.

### OpenShift

In order to deploy this web-client on OpenShift do:

    $ oc new-app centos/nodejs-6-centos7~https://github.com/andrewazores/thermostat-web-client

## Keycloak Configuration

Follow the Thermostat Web-Gateway configuration guide for Keycloak. See the
top of this file for where to place the generated `keycloak.json`.

Additionally, configure the Client on the Keycloak Server with the following
parameters:

`Valid Redirect URIs: http://localhost:8080/*` (or similar)

`Web Origins: +`