2016-03-19 04:36:58 +08:00
|
|
|
///<reference path="../../typings/main.d.ts"/>
|
|
|
|
|
|
|
|
|
|
|
|
import * as _express from 'express';
|
2016-03-20 00:31:42 +08:00
|
|
|
import * as _path from 'path';
|
2016-03-19 04:36:58 +08:00
|
|
|
|
2016-04-10 00:06:29 +08:00
|
|
|
|
|
|
|
import {Utils} from "../../common/Utils";
|
|
|
|
|
|
|
|
import {NextFunction, Request, Response} from "express";
|
|
|
|
|
2016-03-19 04:36:58 +08:00
|
|
|
export class PublicRouter{
|
|
|
|
constructor(private app){
|
2016-04-10 00:06:29 +08:00
|
|
|
this.app.use((req:Request, res:Response, next:NextFunction) => {
|
|
|
|
res.tpl = {};
|
|
|
|
|
|
|
|
res.tpl.user = null;
|
|
|
|
if(req.session.user) {
|
|
|
|
let user = Utils.clone(req.session.user);
|
|
|
|
delete user.password;
|
|
|
|
res.tpl.user = user;
|
|
|
|
}
|
|
|
|
|
|
|
|
return next();
|
|
|
|
});
|
|
|
|
|
2016-03-20 00:31:42 +08:00
|
|
|
this.app.use(_express.static(_path.resolve(__dirname, './../../frontend')));
|
|
|
|
this.app.use('/node_modules',_express.static(_path.resolve(__dirname, './../../node_modules')));
|
|
|
|
|
2016-04-10 00:06:29 +08:00
|
|
|
var renderIndex = (req: Request, res: Response) => {
|
|
|
|
res.render(_path.resolve(__dirname, './../../frontend/index.ejs'),res.tpl);
|
2016-03-20 00:31:42 +08:00
|
|
|
};
|
2016-04-10 00:06:29 +08:00
|
|
|
|
|
|
|
this.app.get(['/','/login',"/gallery*"], renderIndex);
|
2016-03-20 00:31:42 +08:00
|
|
|
|
2016-03-19 04:36:58 +08:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|