0.0.2 • Published 3 years ago
weak-server v0.0.2
Boot
import { Application } from 'weak-server';
const bootstrap = async () => {
const application = new Application({
controllers: [__dirname + '/**/*.controller{.ts,.js}'],
proxy: true,
cors: true,
});
application.listen();
};
bootstrap();
Controller
import { Controller } from 'weak-server';
@Controller('/')
export class HelloworldController {
@Get('hello')
@UseGuards(RolesGaurd)
async get(@Req() req: Request, @Query('q') query: any) {
return new Promise((resolve) =>
resolve({
text: 'Hello World',
msg: 'Message',
}),
);
}
@Get('abc/:id')
async id(@Req() req: Request, @Param('id') query: any) {
return new Promise((resolve) =>
resolve({
text: 'Hello World',
msg: 'Message',
}),
);
}
@Post('users/:id')
getId(@Req() req: Request, @Body() body: any) {
return body;
}
}
Middleware
@Get('hello')
@UseGuards(RolesGaurd)
async get(@Req() req: Request, @Query('q') query: any) {
return new Promise((resolve) =>
resolve({
text: 'Hello World',
msg: 'Message',
}),
);
}