How to use the midway-web.config function in midway-web

To help you get started, we’ve selected a few midway-web examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github midwayjs / sandbox / packages / sandbox-core / src / core / adapter / pandoraAdapter.ts View on Github external
import { inject, config } from 'midway-web';
import {AppSelector, HostSelector} from '../../interface/services/common';
import {IPandoraAdapter} from '../../interface/adapter/IPandoraAdapter';
import {IRemoteExecuteAdapter} from '../../interface/adapter/IRemoteExecuteAdapter';
import {parse as urlparse} from 'url';

export class PandoraAdapter implements IPandoraAdapter {

  @inject('remoteExecuteAdapter')
  protected remoteExecuteAdapter: IRemoteExecuteAdapter;

  @config('pandora')
  protected config;

  async invokeRestful(host: HostSelector, url: string, options?: any) {
    const pandoraRestfulPort = this.config.restfulPort;
    url = url.replace(/^\//, '');
    const cmd = `curl http://127.0.0.1:${pandoraRestfulPort}/${url} 2>/dev/null`;
    const res = await this.remoteExecuteAdapter.exec(host, cmd, options).catch((err) => {
      if (err.message === 'CALL_ERROR: exit 7') {
        err.message = '请求 Pandora 失败,请确保 pandora agent 已正常启动';
      }
      throw err;
    });
    return JSON.parse(res);
  }

  async getProcessesInfo(scopeName: string, ip: string, options?: any): Promise {
github midwayjs / sandbox / packages / sandbox-core / src / core / dataSource / tsdb.ts View on Github external
import {QueryError, QueryOptions, QueryResultItem, SuggestOptions} from './tsdb.core';
import urllib = require('urllib');
import querystring = require('querystring');
import { config, logger, init } from 'midway-web';

export class TSDB {

  @config('tsdb')
  public config;

  @logger()
  public logger;
  defaultQueryOpts = {
    ms: 'true',
  };
  defaultPOSTOpts = {
    msResolution: true,
    showQuery: false,
  };

  protected host: string;
  protected port: string;
  protected prefix: string;
github midwayjs / sandbox / packages / sandbox-core / src / core / dataSource / core.ts View on Github external
import { provide, async, config, logger, scope, ScopeEnum } from 'midway-web';
import { BaseDataSource } from './base';

@scope(ScopeEnum.Singleton)
@async()
@provide('coreDB')
export class CoreDBDataSource extends BaseDataSource {

  @config('coreDB')
  config;

  @logger('coreDBLogger')
  logger;

  name: string = 'coreDB';
}
github midwayjs / sandbox / packages / sandbox-core / src / core / dataSource / dw.ts View on Github external
import { provide, async, config, logger, scope, ScopeEnum } from 'midway-web';
import { BaseDataSource } from './base';

@scope(ScopeEnum.Singleton)
@async()
@provide('dw')
export class DWDataSource extends BaseDataSource {

  @config('dw')
  config;

  @logger('dwLogger')
  logger;

  name: string = 'dw';
}