UNPKG

@aarconada/urserver

Version:

Basic Server definitions to develope REST API with a node + express Server

45 lines (43 loc) 1.26 kB
/** * Created by ubuntu on 14/08/18. */ 'use strict'; const utils = require('./utils'); const server = require('./server')(); class endpointManager { constructor() { this.endpoints = []; this.server = null; this.endpoint = null; } add(endpoint) { this.checkManager(); if (endpoint.isValid()) { endpoint.configuration.help.enabled = endpoint.configuration.help.enabled && this.server.configuration.help.enabled; this.endpoints.push(endpoint); } else { server.debug('Invalid endpointmanager', endpoint); } }; addEndpoint(endpointConfiguration) { this.checkManager(); this.add(this.endpoint.generateInstance(endpointConfiguration)); } checkManager() { if(this.server === null) { this.server = new require('./server')(); } if(this.endpoint === null) { this.endpoint = require('./endpoint'); } } } var endpointManagerInstance; module.exports = function() { if(!endpointManagerInstance) { endpointManagerInstance = new endpointManager(); return endpointManagerInstance; } else { return endpointManagerInstance; } };