Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
import { controller, get, provide } from 'midway';
@provide()
@controller('/')
export class HomeController {
@get('/')
async index(ctx) {
ctx.body = `Welcome to midwayjs!`;
}
}
import { controller, get, provide } from 'midway';
@provide()
@controller('/')
export class HomeController {
@get('*')
async render(ctx) {
await ctx.render('index.html');
await ctx.render('index.html', ctx.clientConfig);
}
}
import { controller, post, provide, Context, inject } from 'midway';
/**
* @controller api 登录接口
*/
@provide()
@controller('/api')
export default class APIController {
@inject()
ctx: Context;
@inject()
userService;
/**
* @summary 注册用户
* @description 注册用户,记录用户账户/密码/
* @router post /api/doRegist
* @request body registUserRequest *body
*/
@post('/doRegist')
async doRegist() {
import { controller, get, provide } from 'midway';
@provide()
@controller('/')
export class HomeController {
@get('/')
async index(ctx) {
ctx.body = `Welcome to midwayjs!`;
}
}
import { controller, get, provide, inject } from 'midway';
@provide()
@controller('/')
export class HomeController {
@inject()
acmService;
@get('/')
async index(ctx: any) {
ctx.body = this.acmService.getData();
}
}
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};
}
}
import { controller, get, provide } from 'midway';
@provide()
@controller('/')
export class HomeController {
@get('/')
async index(ctx) {
ctx.body = `Welcome to midwayjs!`;
}
}
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')
async show(ctx) {
import { Context, controller, inject, get, provide } from 'midway';
@provide()
@controller('/')
export class HomeController {
@inject()
ctx: Context;
@get('/')
async index() {
this.ctx.body = `Welcome to midwayjs!`;
}
}
import { Context, controller, provide, get, post, inject } from 'midway';
import { IUserService } from '../../lib/interface';
@provide()
@controller('/user')
export class UserController {
@inject()
ctx: Context;
@inject('userService')
service: IUserService;
/**
* GET /user/profile
*/
@get('/profile')
async profile() {
const res = await this.service.profile();
this.ctx.body = res.data;
}