0.6.0 • Published 4 years ago

bitspider-agent-baseservice v0.6.0

Weekly downloads
52
License
-
Repository
-
Last release
4 years ago

BitSpider Agent BaseService

const baseservice = require('bitspider-agent-baseservice');
baseservice.express();
baseservice.listen();

Installation

This is a Node.js module available through the npm registry.

Before installing, download and install Node.js.

Node.js 12 or higher is required.

If this is a brand new project, make sure to create a package.json first with the npm init command.

Installation is done using the npm install command:

$ npm install bitspider-agent-baseservice

dia-agents-service is a good example

Features

  1. Implement RESTFul APIs to get and update intelligences to Munew Engine
  2. Default Agent is Service Agent

APIs

express

Create an ExpressJS app, and configure routes, JSON limit, static folder.

const baseservice = require("bitspider-agent-baseservice");
baseservice.express();

Routes

  1. /: return index page
  2. /health: return health status of this server
  3. /agent: return current agent configuration. If agent don't exist then return empty
  4. /log/combined.log: All logs for debug purpose
  5. /log/error.log: Error logs

JSON Limit

100mb

Returns

type

Get or set agent type. Currently support type is ['BROWSEREXTENSION', 'HEADLESSBROSWER', 'SERVICE']. Default is SERVICE type

const baseservice = require("bitspider-agent-baseservice");
baseservice.express();
baseservice.type("HEADLESSBROWSER");

Parameters

  • type:String
    • Optional

Returns

  • String|Object: Type string or BaseService

worker

Get or set worker. Worker responses for collect intelligences. Default it uses service worker.

const { headlessWorker } = require("./workers/headlessWorker");
const baseservice = require("bitspider-agent-baseservice");
baseservice.express();
baseservice.type("HEADLESSBROWSER");
baseservice.worker(headlessWorker);

Parameters

  • worker: Object: worker object
    • Optional

Returns

  • Object: Woker object or BaseService

getPublic

Return absolute path to public folder, anything you store in public folder, you can access by /<path_to_file>.

Returns

  • String: Absolute path to public folder

listen

Start server, similar with express.listen

const baseservice = require('bitspider-agent-baseservice');
baseservice.express();
baseservice.listen();

or

const baseservice = require('bitspider-agent-baseservice');
baseservice.express();
baseservice.listen(9090);

Parameters

  • port: Number: Default will get from process.env.PORT, otherwise 8090
    • Optional

Returns

  • Promise: Start successful, then resolve(true), otherwise reject(err)

logger

Return winston logger, you can use this to add your logs, and view by /log/combined.log or /log/error.log

const baseservice = require('bitspider-agent-baseservice');
const logger = baseservice.logger;
logger.info('Just for test');

Returns

  • Object: winston logger instance
0.6.0

4 years ago

0.5.1

4 years ago

0.5.0

4 years ago

0.4.3

4 years ago

0.3.2

4 years ago

0.3.3

4 years ago

0.3.0

4 years ago

0.3.1

4 years ago

0.2.1

4 years ago

0.2.0

4 years ago

0.1.7

4 years ago

0.1.6

4 years ago

0.1.5

4 years ago

0.1.4

4 years ago

0.1.3

4 years ago

0.1.2

4 years ago

0.1.1

4 years ago