How to use the midway.config function in midway

To help you get started, we’ve selected a few midway 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 / midway-examples / demo-nacos / src / service / namingService.ts View on Github external
import { provide, init, config, scope, ScopeEnum, logger } from 'midway';

const NacosNamingClient = require('nacos').NacosNamingClient;

@provide()
@scope(ScopeEnum.Singleton)
export class NamingService {

  nacosClient;

  @config('nacosNaming')
  nacosConfig;

  @logger()
  logger;

  @init()
  async init() {
    this.nacosClient = new NacosNamingClient({
      ...this.nacosConfig,
      logger: this.logger,
      namespace: 'public',
    });
    await this.nacosClient.ready();

    // 这里的服务名请从 nacos 服务上找
    this.nacosClient.subscribe('nacos.test.3', hosts => {
github midwayjs / midway-examples / demo-sequelize / src / lib / model / db.ts View on Github external
database: string;
  username: string;
  password: string;
}

export interface IDB {
  sequelize: Sequelize;
  options: IDBOptions;
}
@scope(ScopeEnum.Singleton)
@async()
@provide('DB')
export default class DB implements IDB {
  public sequelize: Sequelize;

  @config('sequelize')
  public options: IDBOptions;

  @init()
  public connect() {
    this.sequelize = new Sequelize(
      this.options.database,
      this.options.username,
      this.options.password,
      {
        dialect: this.options.dialect,
        host: this.options.host,
        port: this.options.port,
        timezone: '+08:00',
        logging: false,
      },
    );
github midwayjs / midway-examples / demo-plugin-egg-jwt / src / app / controller / home.ts View on Github external
import { controller, config, plugin, get, provide, Context, inject } from 'midway';

@provide()
@controller('/')
export class HomeController {

  @inject()
  ctx: Context;

  @plugin()
  jwt;

  @config('jwt')
  jwtConfig;

  @get('/token')
  async api(ctx: Context) {
    const token = this.jwt.sign({ foo: 'bar' }, this.jwtConfig.secret);
    ctx.body = token;
  }

}

midway

A Node.js Serverless Framework for front-end/full-stack developers. Build the application for next decade.

MIT
Latest version published 3 years ago

Package Health Score

60 / 100
Full package analysis