Server IP : 85.214.239.14 / Your IP : 18.222.164.159 Web Server : Apache/2.4.62 (Debian) System : Linux h2886529.stratoserver.net 4.9.0 #1 SMP Mon Sep 30 15:36:27 MSK 2024 x86_64 User : www-data ( 33) PHP Version : 7.4.18 Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare, MySQL : OFF | cURL : OFF | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : OFF Directory : /proc/2/task/2/root/lib/node_modules/pm2/node_modules/@pm2/js-api/src/ |
Upload File : |
'use strict' const Endpoint = require('./endpoint') const logger = require('debug')('kmjs:namespace') module.exports = class Namespace { constructor (mapping, opts) { logger(`initialization namespace ${opts.name}`) this.name = opts.name this.http = opts.http this.endpoints = [] this.namespaces = [] logger(`building namespace ${opts.name}`) for (let name in mapping) { let child = mapping[name] if (typeof mapping === 'object' && !child.route) { // ignore the 'default' namespace that should bind to the parent namespace if (name === 'default') { // create the namespace const defaultNamespace = new Namespace(child, { name, http: this.http, services: opts.services }) this.namespaces.push(defaultNamespace) // bind property of the default namespace to this namespace for (let key in defaultNamespace) { if (key === 'name' || key === 'opts') continue this[key] = defaultNamespace[key] } continue } // if the parent namespace is a object, the child are namespace too this.addNamespace(new Namespace(child, { name, http: this.http, services: opts.services })) } else { // otherwise its an endpoint if (child.service && opts.services && opts.services[child.service.name]) { child.service.baseURL = opts.services[child.service.name] } this.addEndpoint(new Endpoint(child)) } } // logging namespaces if (this.namespaces.length > 0) { logger(`namespace ${this.name} contains namespaces : \n${this.namespaces.map(namespace => namespace.name).join('\n')}\n`) } // logging endpoints if (this.endpoints.length > 0) { logger(`Namespace ${this.name} contains endpoints : \n${this.endpoints.map(endpoint => endpoint.route.name).join('\n')}\n`) } } addNamespace (namespace) { if (!namespace || namespace.name === this.name) { throw new Error(`A namespace must not have the same name as the parent namespace`) } if (!(namespace instanceof Namespace)) { throw new Error(`addNamespace only accept Namespace instance`) } this.namespaces.push(namespace) this[namespace.name] = namespace } addEndpoint (endpoint) { if (!endpoint || endpoint.name === this.name) { throw new Error(`A endpoint must not have the same name as a namespace`) } if (!(endpoint instanceof Endpoint)) { throw new Error(`addNamespace only accept Namespace instance`) } this.endpoints.push(endpoint) this[endpoint.name] = endpoint.build(this.http) } }