import {flank} from "flank";
import * as bodyParser from "body-parser";
import * as express from "express";
import * as path from "path";
class myValidator implements flank.IValidator
{
constructor()
{
this.name = this.constructor.name
}
name:string
validate = function(obj : Object, key : string, descriptor: PropertyDescriptor, args : any[], i : number)
{
if(args[i] != "Hello")
return {isValid:false, message:"You didn't say Hello World"};
else
return {isValid:true}
}
}
let myvalidator = new myValidator()
export class DemoController extends flank.express.Controller
{
constructor () {
super(true)
var p : any = this
p.on('Prop', ( args : any[])=>{ console.log(args) })
}
@flank.NotifyPropertyChanged(true)
public Prop : string;
@flank.Validate()
@flank.Route('/demo/:message')
public Demo(@flank.Validator(myvalidator) message:string = "Hello World"): any
{
this.Prop = message
return message
}
}
export class Server
{
public app: express.Application;
constructor()
{
this.app = express();
this.config();
this.routes();
}
public config()
{
this.app.use(bodyParser.json());
this.app.use(bodyParser.urlencoded({
extended: true
}));
this.app.use(function(err: any, req: express.Request, res: express.Response, next: express.NextFunction)
{
err.status = 404;
next(err);
});
}
public routes()
{
this.app.use(flank.express.Router({},[DemoController]))
}
}