1.1.0 • Published 2 years ago

@foxify/config v1.1.0

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

Foxify Config

Test CodeCov

Foxify Configuration

Table of Content

Installation

In case of using GitHub package registry, the package name will be @foxifyjs/config.

NPM

npm i @foxify/config

PNPM

pnpm add @foxify/config

Yarn

yarn add @foxify/config

Usage

Create the foxify.config.js file at the root of your project. (Optional)

In case of the config file missing, the default values will be used.

ConfigTypeDefaultDescription
envproduction, development, testprocess.env.NODE_ENV or developmentNode.js environment.
xPoweredByBooleantrueIndicates whether the X-Powered-By header should be present or not.
workersInteger between 1 and number of cpu cores1Number of Node.js cluster workers to be created. In case of 1 Node.js cluster workers won't be used.
etag(body: string / Buffer, encoding?: BufferEncoding) => string-ETag response header value generator.
serverObject-Server config.
server.protocolhttp, httpshttpServer protocol.
server.hostnameStringlocalhostServer hostname.
server.portInteger between 0 and 655353000Server port.
subdomainObject-Subdomain config.
subdomain.offsetNon-negative integer2The number of dot-separated parts of the host to remove to access subdomain.
jsonObject-JSON config.
json.escapeBooleanfalseEnable escaping JSON responses from the res.json, res.jsonp, and res.send APIs.
json.replacer(key: string, value: unknown) => unknown-The replacer argument used by JSON.stringify.
json.spacesNon-negative integer0The space argument used by JSON.stringify. This is typically set to the number of spaces to use to indent prettified JSON.
jsonpObject-JSONP config.
jsonp.callbackStringcallbackThe JSONP callback name.
queryObject-Request query string config.
query.parser(queryString: string) => Record<string, any>qs.parseA custom query string parsing function will receive the complete query string, and must return an object of query keys and their values.
proxyObject-Proxy config.
proxy.trust(ip: string, hopIndex: number) => boolean() => falseIndicates whether the app is behind a front-facing proxy, and to use the X-Forwarded-* headers to determine the connection and the IP address of the client.

The exported config values are frozen using Object.freeze.

ECMAScript

Config file contents (foxify.config.js):

export default {
  env: "development",
  xPoweredBy: true,
  workers: 1,
  server: {
    protocol: "http",
    hostname: "localhost",
    port: 3000,
  },
  subdomain: {
    offset: 2,
  },
  json: {
    escape: false,
    spaces: 0,
  },
  jsonp: {
    callback: "callback",
  },
  query: {
    parser: qs.parse,
  },
  proxy: {
    trust: () => false,
  },
};

Consume the config values:

import config from "@foxify/config";

CommonJS

Config file contents (foxify.config.js):

module.exports = {
  env: "development",
  xPoweredBy: true,
  workers: 1,
  server: {
    protocol: "http",
    hostname: "localhost",
    port: 3000,
  },
  subdomain: {
    offset: 2,
  },
  json: {
    escape: false,
    spaces: 0,
  },
  jsonp: {
    callback: "callback",
  },
  query: {
    parser: qs.parse,
  },
  proxy: {
    trust: () => false,
  },
};

Consume the config values:

const config = require("@foxify/config").default;

Versioning

We use SemVer for versioning. For the versions available, see the releases on this repository.

Authors

See also the list of contributors who participated in this project.

License

This project is licensed under the MIT License - see the LICENSE file for details