Documentation, Uncategorized

Multiple Environments with Loopback 4

When configuring multiple environments for a Loopback 4 Application, it can appear less straight forward than with Loopback 3, so here is a quick fix for how to get over this obstacle as elegantly as possible in 5 minutes.

  1. Import dotenv and create a .env file in the root of the app.
  2. Put your database configuration in this file.
  3. Empty the existing datasource file so it contains an empty JSON (file is required by compiler and the bootstrapping).
  4. Add the code below to the application.ts file in the src directory.
  5. Don’t forget to require the dotenv from the run command.
this.bind('datasources.default').to(new DefaultDataSource());
this.dataSource(new DefaultDataSource());
this.bind('datasources.config.default').to({
  name: 'default',
  connector: 'mongodb',
  hostname: process.env.DB_DEFAULT_HOSTNAME,
  port: process.env.DB_DEFAULT_PORT,
  user: process.env.DB_DEFAULT_USER,
  password: process.env.DB_DEFAULT_PASSWORD,
  database: process.env.DB_DEFAULT_DATABASE,
  useNewUrlParser: process.env.DB_DEFAULT_USENEWURLPARSER,
  authSource: process.env.DB_DEFAULT_AUTHSOURCE
});
this.bind('datasources.default').toClass(DefaultDataSource);

This is a quick fix intended to help move on if in a pickle, I will refine this further so the application will check the process.env.NODE_ENV variable instead and load the corresponding file.

For the original inspiration to this post, head over here: https://medium.com/p/8f085399268/responses/show

 

Advertisements
Documentation

QuickFix how to deploy a Loopback 4 Application to Heroku

When you are prototyping, sometimes you just need something to work, this was my case with a new experiment I’m working using Loopback 4 which I wanted to deploy for to Heroku for some rapid testing.

Generally CLI generated App’s doesn’t like environments like Heroku too much and since I later will deploy to DigitalOcean through some Docker containers, I just needed a QuickFix.

Anyways, let’s get to the point… this is a very opiniated post which takes for granted you are using the exact same development workflow that I have, if not, post a comment and I will do my best to help you out.

  1. Remove the /dist entry from .gitignore so it will be committed to Git, and subsequently caught by the CD routine running on Heroku through the GitHub Webhook.
  2. Remove the prestart script entry from package.json.
  3. Remove the “-r source-map-support/register” from the start script entry in package.json.

Now you are good to deploy it to Heroku via GitHub, however don’t forget to build before you commit.

 

Documentation

CORS with Loopback & Angular Apps

To get the two running nicely together in respect to CORS, don’t forget to disable the origin only default policy of Loopback by setting the origin in the CORS configuration to “*” in the middleware.json file.

{
  ...
  "initial": {
    "compression": {},
    "cors": {
      "params": {
        "origin": "*",
        "credentials": true,
        "maxAge": 86400
      }
    }
    ...
  }
}

 

PostgreSQL

Enable UUID on PostgreSQL

Sometimes we want to have native support for UUID’s in Postgres, fortunately there is already a ready-made extension that makes it easy.

Enter the “uuid-ossp” extension… fortunately furthermore, its very easy to use…

  1. Enable the extension:

    CREATE EXTENSION IF NOT EXISTS “uuid-ossp”

  2. Set default value on the column to “expression” and use the following default value:

    uuid_generate_v4()

Uncategorized

Keyboard Shortcut for Inserting Comment in Word for Mac

If you have come to this post, chances are you like me found yourself tired of adding comments by using the mouse and was surprised that the “Insert Comment” didn’t feature a keyboard shortcut… but dispair not, the solution is here…

Very intuitively (not really), the keyboard shortcut to insert comment is

Command + Alt + A

If you want to see for yourself or set it to something else, you can find the setting here:

Tools > Customize Keyboard > Insert > InsertAnnotation

Now, you can enjoy the thrill of being able to review documents galore without having to let your fingers leave your keyboard… what a production boost, eh !?

Labs

Early Fuse Experiment… porting the Angular-Resource Module to Fuse

Fuse is a cool new front-end technology, probably the coolest alternative right now creating cross platform mobile applications with Native Performance…

I do a lot of CRUD applications, so as part of the learning process, I decided to experiment with how it would be to port the omni-present Angular-Resource (https://docs.angularjs.org/api/ngResource/service/$resource) module to be used in Fuse.

This is still very very early stuff, I just wanted to share it quickly to inspire other people just starting out with Fuse to tinker themselves and share their own cool stuff…

Anyways, enough talking, let’s get to it…

My first task was to use the fetch operation which is the recommended way to make network requests via HTTP, it’s a first-class citizen in Fuse which resembles the same status it will take the browser in the future…
You can read more about the proposed standard for the Fetch API here:
https://developer.mozilla.org/en/docs/Web/API/Fetch_API

My experiment is based on the lab recently published by Jake from FuseTools… basically just replacing his call to fetch with a call to the Get operation on my resource implementation, which eventually wraps and uses fetch…
https://github.com/yupferris/fuse-example-fetching-and-displaying-data

It illustrates how it’s relatively easy to implement a 3rd party reusable library and how it can be imported into your Fuse project.

The standard used is CommonJS, and contrary to what FuseTools document themselves, I found during my experiment that its possible to both use the advised syntax of module.exports, but also the less convoluted syntax of exports.[memberName], which is the default for e.g. the TypeScript compiler.

I have included a link to an archive at the end of the post which contains all the files required for the experiment, please feel free to play around with it.

If you are interested in contributing to the further development of the fuse-resource module, please take a look here (https://github.com/pmoelgaard/fuse-resource).

Until an official TypeScript definition is released for Fuse, I’m maintaining my own definition which allows me to compile against the global members of Fuse…
https://github.com/pmoelgaard/fuse

Now, this is very early stuff, so please understand that it’s very rough around the edges and covered in wet paint, and that I’m only sharing it because I’m very excited of where Fuse is taking the next generation of cross-platform development for both mobile, but also desktop, which is one of the really cool features of Fuse…

Example usage

Download the project files from here: http://cl.ly/16280D0n1L0I