@balljs/core
v0.0.3
Published
A server side framework
Downloads
2
Readme
Nodejs server side framework.
Documents place see https://github.com/wangshihao111/balljs
Example
import {
Controller,
Get,
useInterceptor,
RouterCtx,
autoWired,
AppCtx,
Post,
Value,
} from '@balljs/core';
import { InjectConnection } from '@balljs/plugin-typeorm';
import { AuthInterceptor } from '../interceptors/AuthInterceptor';
import { DBService } from '../services/DBService';
import { UserService } from '../services/UserService';
@useInterceptor([AuthInterceptor])
@Controller('/')
export class IndexController {
age: number;
// load service
@autoWired(UserService)
userService!: UserService;
@autoWired(DBService)
db!: DBService;
// load properties
@Value('appName')
appName!: string;
@Value('server')
server!: any;
// typeorm plugin
@InjectConnection('test')
connection: any;
constructor(private appCtx: AppCtx) {
this.age = 999;
}
// route handler
@Get('/hello')
index(ctx: RouterCtx) {
console.log('Value appName', this.appName, this.server);
console.log(this.appCtx.orm, this.connection);
console.log(
this.userService,
this.db.user,
this.userService === this.db.user
);
console.log(ctx.appCtx.render?.(), ctx.appCtx.ctx.request.query);
ctx.appCtx.ctx.body = ctx.body + 'hello world';
}
// route handler
@Post('/hello')
postIndex(ctx: RouterCtx) {
ctx.body = ctx.request.body;
}
}