Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Version History

« Previous Version 3 Next »

After downloading the CHEFS source code from: https://github.com/bcgov/common-hosted-form-service

Duplicate the file /common-hosted-form-service/app/config/default.json into a new file called /common-hosted-form-service/app/config/local.json

Make the necessary changes so that the local.json file looks like:

{
  "db": {
    "database": "chefs",
    "host": "localhost",
    "port": "5432",
    "username": "app",
    "password": "admin"
  },
  "files": {
    "uploads": {
      "enabled": "true",
      "fileCount": "1",
      "fileKey": "files",
      "fileMaxSize": "25MB",
      "fileMinSize": "0KB",
      "path": "files"
    },
    "permanent": "localStorage",
    "localStorage" : {
      "path": "myfiles"
    },
    "objectStorage": {
      "accessKeyId": "nr-iit-showcase",
      "bucket": "egejyy",
      "endpoint": "https://nrs.objectstore.gov.bc.ca",
      "key": "chefs/dev/",
      "secretAccessKey": "anything"
    }
  },
  "frontend": {
    "apiPath": "api/v1",
    "basePath" : "/app",
    "keycloak": {
      "clientId": "chefs",
      "realm": "cp1qly2d",
      "serverUrl": "http://localhost:8082"
    }
  },
  "server": {
    "apiPath": "/api/v1",
    "basePath" : "/app",
    "bodyLimit": "30mb",
    "keycloak": {
      "clientId": "chefs-backend",
      "realm": "cp1qly2d",
      "serverUrl": "http://localhost:8082",
      "clientSecret": "XXXXXXXXXXXX"
    },
    "logLevel": "http",
    "port": "8080",
    "rateLimit" : {
      "public": {
        "windowMs": "900000",
        "max": "100"
      }
    }
  },
  "serviceClient": {
    "commonServices": {
      "ches": {
        "endpoint": "https://ches-dev.apps.silver.devops.gov.bc.ca/api"
      },
      "cdogs": {
        "endpoint": "https://cdogs-dev.apps.silver.devops.gov.bc.ca/api"
      },
      "tokenEndpoint": "https://dev.oidc.gov.bc.ca/auth/realms/jbd6rnxw/protocol/openid-connect/token",
      "username": "CHEFS_SERVICE_CLIENT",
      "password": "CHEFS_SERVICE_PASSWORD"
    }
  }
}

You’ll need the docker-compose file which you can copy from or download from here: https://github.com/jasonchung1871/common-hosted-form-service/blob/dockerize/docker-compose.yml

In the same directory as this docker-compose file, you’ll need to create directories in the following structure:

  • docker

    • imports

      • keycloak

Copy or download the realm-export.json file from https://github.com/jasonchung1871/common-hosted-form-service/blob/dockerize/docker/imports/keycloak/realm-export.json and place it inside of the docker/imports/keycloak directory you've just created.

Afterwards, open the realm-export.json file and change the following settings:

Search for XXXXXXXXXXXX and you can change this to any value you want. Afterwards, you must copy this value and paste it in your CHEFS configuration so that the CHEFS API can connect to your keycloak instance. You can do this by opening the file /common-hosted-form-service/app/config/local.json and replacing the value for..

{
  ...
  server: {
    ...
    keycloak: {
      ...
      clientSecret: "XXXXXXXXXXXX"
      ...
    },
    ...
  },
  ...
}

In the same realm-export.json file:

Search for YYYYYYYYYYYY and replace it with the client id you obtained from the Pathfinder SSO page.

Search for ZZZZZZZZZZZZ and replace it with the client secret you obtained from the Pathfinder SSO page.

Now you can run Keycloak and PostgreSQL by heading into the directory where your docker-compose.yml file is located and opening a terminal there.

Run the following command:

docker compose up

This will start up an instance for your Keycloak and PostgreSQL containers. If you don’t want to keep the terminal open, you can append a -d to the end of the command above.

Now open a terminal in the directory /common-hosted-form-service/app and run the following commands:

npm install
npm run migrate
npm run seed:run
npm run serve

This will start the process for the CHEFS API.

Open another terminal in the directory /common-hosted-form-service/app/frontend and run the following commands:

npm install
npm run serve

This will start the process for the CHEFS frontend.

Troubleshooting

Cannot connect to the Docker daemon:

Before running docker compose up, you will need to start the Docker daemon. Most Linux distributions use systemctl to start services and the macOS equivalent is launchctl. Use the following command to run the Docker daemon:

sudo systemctl start docker

or

sudo launchctl start docker

for Mac users.

If you are using the Docker desktop app, starting the application and then running docker compose up will also work.

App not loading on localhost

After running npm run serve, the App should be running at http://localhost:8081/app/, but if you have issues where it is not loading, try the following:

  1. Disable checkLoginIFrame

    Edit the loadKeycloack(config) function in /common-hosted-form-service/app/frontend/src/main.js to look like:

    function loadKeycloak(config) {
      Vue.use(VueKeycloakJs, {
        init: { onLoad: 'check-sso', checkLoginIframe: false },
        config: {
          clientId: config.keycloak.clientId,
          realm: config.keycloak.realm,
          url: config.keycloak.serverUrl
        },
        onReady: () => {
          initializeApp(true, config.basePath);
        },
        onInitError: error => {
          console.error('Keycloak failed to initialize'); // eslint-disable-line no-console
          console.error(error); // eslint-disable-line no-console
        }
      });
    }

setting the checkLoginIframevalue to false.

Before pushing your code, remember to revert the changes to main.js, removing the checkLoginIFrame variable from the code.

2. CORS Unblock Extension

In case you get an error message where access is blocked by CORS policy similar to the one below:

Download the CORS Unblock extension for chrome and enable the following settings:

This extension disables CORS security and should allow you to load the local instance of your application.

  • No labels