0.8.8 • Published 5 years ago

nodecloud-boot v0.8.8

Weekly downloads
1
License
MIT
Repository
-
Last release
5 years ago

NodeCloud-Boot

Usage

npm install nodecloud-boot --save

Using with sequelize and mysql:

import NCBoot from 'nodecloud-boot';
import Koa from 'koa';

const app = new Koa();

const configPath = __dirname;
const ncBoot = NCBoot.getInstance(configPath);

function startCallback(webConfig) {
    //do something before the web server start.
    
    return app.callback();
}

function endCallback() {
    //doing something before the process exit.
    
}

function initModels(sequelize) {
    //init sequelize models in this.
    
}

ncBoot.init({initModels})(startCallback, endCallback);

const consul = ncBoot.consul;
const sequelize = ncBoot.sequelize;
const client = ncBoot.client;
const loadbalance = ncBoot.loadbalance;
const logger = ncBoot.logger;

Using without sequelize:

import NCBoot from 'nodecloud-boot';
import Koa from 'koa';

const app = new Koa();

const configPath = __dirname;
const ncBoot = NCBoot.getInstance(configPath);

function startCallback(webConfig) {
    //do something before the web server start.
    
    return app.callback();
}

function endCallback() {
    //doing something before the process exit.
    
}

ncBoot.initApp(startCallback, endCallback);

const consul = ncBoot.consul;
const sequelize = ncBoot.sequelize;
const client = ncBoot.client;
const loadbalance = ncBoot.loadbalance;
const logger = ncBoot.logger;

Config file bootstrap-${env}.js

import path from 'path';

module.exports = {
    web: {
        serviceId: null,
        serviceName: 'multi-cloud-schedule-service',
        port: 3006
    },
    consul: {
        host: '192.168.0.30',
        port: 8500,
        discoveryHost: null,
        timeout: '1s',
        interval: '10s'
    },
    config: {
        server: {
            name: 'multi-cloud-config-service',
            url: '/multi-cloud-config-service/v1/config/:service/:env/inner',
            interval: 60000,
            watch: false,
            client: 'multi-cloud-schedule-service'
        },
        local: {
            path: __dirname,
            service: 'config',
            ext: 'js'
        }
    },
    logger: {
        path: path.resolve(__dirname, '../log')
    },
    loadbalance: {
        strategy: 'random',
        request: {
            forever: true,
            timeout: 60000
        }
    },
    brake: {
        enable: true,
        timeout: 60000
    }
};

Config file config-${env}.js

module.exports = {
    dataSource: {
        database: 'test',
        host: '127.0.0.1',
        username: 'root',
        password: 'root',
        pool: {
            min: 10,
            max: 100,
            idle: 20000,
            acquire: 20000
        }
    }
};

API

NCBoot.getInstance(path): ncBoot

  • path: The position of the config file bootstrap-${NODE_ENV}.js
  • ncBoot: It will return the nodecloud-boot instance.

ncBoot.initApp(startCallback, endCallback)

  • startCallback: function(webConfig), A callback function before server started.
  • endCallback: function() A callback function before server stopped.

ncBoot.init(obj): {initApp(startCallback, endCallback)}

  • obj: {initModels: function(sequelize)}
  • initApp

ncBoot.consul

The consul instance, you can use ncBoot.consul.client to get the original node-consul instance.

ncBoot.sequelize

The sequelize instance.

ncBoot.client

An http client with loadbalance and circuit.

ncBoot.loadbalance

An http client with loadbalance.

ncBoot.logger

The logger instance.

0.8.8

5 years ago

0.8.6

5 years ago

0.8.5

5 years ago

0.8.4

5 years ago

0.8.3

5 years ago

0.8.2

5 years ago

0.8.1

5 years ago

0.8.0

5 years ago

0.7.0

6 years ago

0.6.0

6 years ago

0.5.0

6 years ago

0.4.4

6 years ago

0.4.3

6 years ago

0.4.2

6 years ago

0.4.1

6 years ago

0.4.0

6 years ago

0.3.12

6 years ago

0.3.11

6 years ago

0.3.10

6 years ago

0.3.9

6 years ago

0.3.8

6 years ago

0.3.7

6 years ago

0.3.6

6 years ago

0.3.5

6 years ago

0.3.4

6 years ago

0.3.3

6 years ago

0.3.2

6 years ago

0.3.1

6 years ago

0.3.0

6 years ago

0.2.9

6 years ago

0.2.8

6 years ago

0.2.7

6 years ago

0.2.6

6 years ago

0.2.5

6 years ago

0.2.4

6 years ago

0.2.3

6 years ago

0.2.2

6 years ago

0.2.1

6 years ago

0.2.0

6 years ago

0.1.6

6 years ago

0.1.5

6 years ago

0.1.4

6 years ago

0.1.3

6 years ago

0.1.2

6 years ago

0.1.1

6 years ago

0.1.0

6 years ago

0.0.5

7 years ago

0.0.4

7 years ago

0.0.3

7 years ago

0.0.2

7 years ago

0.0.1

7 years ago