How to use the midway.provide 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 ykfe / egg-react-ssr / example / ssr-with-ts / src / app / controller / page.ts View on Github external
import { controller, get, provide, inject, Context } from 'midway'
import { Config } from 'ykfe-utils'
import renderToStream from 'ykfe-utils/lib/renderToStream'
import { IApiService } from '../../interface'

const ssrConfig: Config = require('../../../config/config.ssr')

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

  @inject()
  ctx: Context

  @inject('ApiService')
  service: IApiService

  async index () {
    try {
      // Page为webpack打包的chunkName,项目默认的entry为Page
      this.ctx.type = 'text/html'
      this.ctx.status = 200
      this.ctx.apiService = this.service.index // 将service挂载到上下文对象
      const config = Object.assign(this.ctx.app.config, ssrConfig)
github midwayjs / midway-examples / demo-plugin-egg-graphql / src / app / controller / user.ts View on Github external
import { controller, get, inject, provide } from 'midway';
import { IUserService, IUserResult } from '../../interface';

@provide()
@controller('/user')
export class UserController {
  @inject('userService')
  service: IUserService;

  @get('/:id')
  async getUser(ctx): Promise {
    const id: number = ctx.params.id;
    const user: IUserResult = await this.service.getUser({id});
    ctx.body = {success: true, message: 'OK', data: user};
  }
}
github midwayjs / midway / benchmark / fixtures / midway-request-scope / src / app / controller / user.ts View on Github external
import { controller, get, inject, provide } from 'midway';
import { IUserResult, IUserService } from '../../interface';

@provide()
@controller('/user')
export class UserController {
  @inject('userService')
  service: IUserService;

  @get('/:id')
  async getUser(ctx): Promise {
    const id: number = ctx.params.id;
    const user: IUserResult = await this.service.getUser({id});
    ctx.body = {success: true, message: 'OK', data: user};
  }
}
github midwayjs / midway / packages / midway-init / boilerplate / midway-ts-boilerplate / boilerplate / src / app / controller / home.ts View on Github external
import { Context, inject, controller, get, provide } from 'midway';

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

  @inject()
  ctx: Context;

  @get('/')
  async index() {
    this.ctx.body = `Welcome to midwayjs!`;
  }
}
github midwayjs / midway-examples / demo-sequelize / src / lib / service / post.ts View on Github external
import { inject, provide } from 'midway';
import { IPostModel } from '../model/post';
import { IListQueryOpt, IListQueryOptions, IPostService } from './post.i';

@provide('postService')
export class PostService implements IPostService {
  @inject('PostModel')
  public model: IPostModel;

  public async list({ offset = 0, limit = 10, title }: IListQueryOptions) {
    const options: IListQueryOpt = {
      offset,
      limit,
      attributes: ['id', 'title', 'content', 'created_at', 'updated_at'],
      order: [['updated_at', 'desc'], ['id', 'desc']],
    };
    if (title) {
      options.where = {
        title,
      };
    }
github midwayjs / midway / benchmark / fixtures / midway-sample / src / lib / service / user.ts View on Github external
import { provide } from 'midway';
import { IUserOptions, IUserResult, IUserService } from '../../interface';

@provide('userService')
export class UserService implements IUserService {

  async getUser(options: IUserOptions): Promise {
    return new Promise((resolve) => {
      setTimeout(() => {
        resolve({
          id: options.id,
          username: 'mockedName',
          phone: '12345678901',
          email: 'xxx.xxx@xxx.com',
        });
      }, 100);
    });
  }
}
github midwayjs / midway-examples / demo-sequelize / src / app / controller / post.ts View on Github external
/**
 * midway sequelize 使用范例
 * 参考
 * - https://github.com/midwayjs/midway-examples/tree/master/demo-sequelize
 * - http://docs.sequelizejs.com/manual/typescript.html
 */
import { controller, del, get, inject, patch, post, provide } from 'midway';
import { IPostService } from '../../interface';

@provide()
@controller('/post/')
export class PostController {
  @inject('postService')
  public service: IPostService;

  /**
   * GET /post
   */
  @get('/')
  public async index(ctx) {
    const query = {
      limit: parseInt(ctx.query.limit, 10) || 10,
      offset: parseInt(ctx.query.offset, 10) || 0,
    };
    ctx.body = await this.service.list(query);
  }
github alibaba / ice / packages / ice-midway-template / templates / server / src / app / controller / home.ts View on Github external
import { controller, get, provide } from 'midway';

@provide()
@controller('/')
export class HomeController {
  @get('/')
  async index(ctx) {
    await ctx.render('index.ejs', {
      assets: ctx.assets,
    });
  }
}
github midwayjs / midway-examples / demo-sequelize-typescript / src / app / controller / post.ts View on Github external
import { controller, get, post, provide, inject } from 'midway';
import { IPostService } from '../../interface';

@provide()
@controller('/post')
export class PostController {
  @inject()
  postService: IPostService;

  @get('/')
  async index(ctx) {
    const query = {
      limit: parseInt(ctx.query.limit, 10) || 10,
      offset: parseInt(ctx.query.offset, 10) || 0,
    };

    ctx.body = await this.postService.list(query);
  }

  @get('/find')
github midwayjs / midway-examples / demo-plugin-egg-graphql / src / app / controller / home.ts View on Github external
import { controller, get, provide } from 'midway';

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

  @get('/')
  async index(ctx) {
    ctx.body = `Welcome to midwayjs!`;
  }
}

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