/nora-service

NORA backend service

Primary LanguageTypeScript

nora-service

NORA (https://node-red-google-home.herokuapp.com) backend service deployed in Heroku.

Deployment instructions: (small guide on how to run nora-service on your own Heroku)

Needed:

HEROKU

  • Create a new Account and then a new app. From Overview, add new add-on "Heroku Postgres" To deploy, you can either use the heroku cli or connect your github account. (do not deploy anything yet)
  • Keep this browser tab open

FIREBASE

  • Create a new Firebase Project and name it accordingly.
  • Navigate to Project Overview - Project Settings - General and create a new web app.
  • Navigate to Project Overview - Project Settings - Service Accounts and generate new private key
  • Navigate to Develop - Authentication - Users - Set up sign-in method - Google - enable - check that Web SDK configuration is filled in.
  • Keep this browser tab open

Google Api Console

Google Actions

CONFIG HEROKU ENV VARS

In Heroku go to Settings - Config Vars and add

env vars

JWT_COOKIE = nora:auth
JWT_SECRET = downloaded service account json from firebase - private_key
OAUTH_ID = api console - credentials - oauth 2.0 client ids - web client - Client ID
OAUTH_SECRET = api console - credentials - oauth 2.0 client ids - web client - Client secret
PROJECT_ID = firebase - settings -general - your apps - project id
SERVICE_ACCOUNT_ISSUER =  downloaded service account json from firebase - client_email
SERVICE_ACCOUNT_KEY =  downloaded service account json from firebase - private_key (format it as multiline)
FIREBASE_APIKEY = firebase - settings -general - your apps
FIREBASE_AUTHDOMAIN = firebase - settings -general - your apps

USER.REPOSITORY.TS

Modify src/services/user.repository.ts

To create the Database Tables modify this lines:

(async function () {
    const service = new PostgressService();
    await service.query(`
        CREATE TABLE IF NOT EXISTS appuser (
            uid VARCHAR(30) CONSTRAINT pk PRIMARY KEY,
            linked boolean DEFAULT false
        )`
    );

    await service.query('ALTER TABLE appuser ADD COLUMN IF NOT EXISTS noderedversion integer DEFAULT 1');
	await service.query('ALTER TABLE appuser ADD COLUMN IF NOT EXISTS refreshtoken integer DEFAULT 1');
})().catch(err => {
    console.error(err);
}).then(() => {
    console.log('done');
});

PUSH

THAT'S IT, you are ready to deploy to Heroku! Build the app and the schema with npm run heroku-postbuild before deploying. To deploy follow the instructions from the Heroku website or if you linked your account in Heroku with Github just push to github.

README DISCLAIMER

The instructions might be incomplete. For issues with the instructions please create an issue and we'll take another look,