0.0.8 • Published 1 year ago

@ghii/http-loader v0.0.8

Weekly downloads
159
License
MIT
Repository
github
Last release
1 year ago

GHII - HTTP LOADER

Http loader is a ghii loader. It is used to load the configurations of a nodejs application by calling an endpoint which returns a json with the configurations to be injected into the application.

How to install:

npm install @ghii/http-loader

Configuration in yaml:

env: development
app:
  version: "0.0.1"
  name: "ghii-test"

in JSON:

{
  "env": "development",
  "app": {
    "version": "0.0.1",
    "name": "ghii-test"
  }
}

Usage example:

import ghii from "@ghii/ghii";
import httpLoader from "@ghii/http-loader";

const options = ghii((T) =>
  T.Object({
    env: T.Union([T.Literal("development"), T.Literal("production")], {
      default: "development",
    }),
    app: T.Object(
      {
        name: T.String({ default: "test" }),
        version: T.String(),
      },
      { additionalProperties: false, default: {} }
    ),
  })
).loader(
  //example url http://localhost:4000/.wellknown.json
  httpLoader(process.env.WELLKNOWN_URL!, {
    throwOnError:  process.env.NODE_ENV !== 'development', //silent mode
    logger: (err, msg) => {
      if (err) {
        customLogger.error(err, msg);
      } else {
        customLogger.debug(msg);
      }
    },
  })
);

export default options;

Related

0.0.8

1 year ago

0.0.7

1 year ago

0.0.5

1 year ago

0.0.6

1 year ago

0.0.3

3 years ago

0.0.4

3 years ago

0.0.2

3 years ago

0.0.1

3 years ago