2016-05-26 09:44:13 +02:00
|
|
|
///<reference path="../../typings/index.d.ts"/>
|
2016-03-18 21:36:58 +01:00
|
|
|
|
2016-05-09 17:04:56 +02:00
|
|
|
import * as _express from "express";
|
2016-04-09 18:06:29 +02:00
|
|
|
import {NextFunction, Request, Response} from "express";
|
2016-05-09 17:04:56 +02:00
|
|
|
import * as _path from "path";
|
|
|
|
import {Utils} from "../../common/Utils";
|
2016-05-10 21:33:58 +02:00
|
|
|
import {Config} from "../config/Config";
|
2016-04-09 18:06:29 +02:00
|
|
|
|
2016-05-09 17:04:56 +02:00
|
|
|
export class PublicRouter {
|
|
|
|
constructor(private app) {
|
2016-04-09 18:06:29 +02:00
|
|
|
this.app.use((req:Request, res:Response, next:NextFunction) => {
|
|
|
|
res.tpl = {};
|
|
|
|
|
|
|
|
res.tpl.user = null;
|
2016-05-09 17:04:56 +02:00
|
|
|
if (req.session.user) {
|
2016-04-09 18:06:29 +02:00
|
|
|
let user = Utils.clone(req.session.user);
|
|
|
|
delete user.password;
|
|
|
|
res.tpl.user = user;
|
|
|
|
}
|
2016-05-10 21:33:58 +02:00
|
|
|
res.tpl.clientConfig = Config.Client;
|
2016-04-09 18:06:29 +02:00
|
|
|
|
|
|
|
return next();
|
|
|
|
});
|
2016-05-09 17:04:56 +02:00
|
|
|
|
2016-03-19 17:31:42 +01:00
|
|
|
this.app.use(_express.static(_path.resolve(__dirname, './../../frontend')));
|
2016-05-09 17:04:56 +02:00
|
|
|
this.app.use('/node_modules', _express.static(_path.resolve(__dirname, './../../node_modules')));
|
2016-03-19 17:31:42 +01:00
|
|
|
|
2016-05-09 17:04:56 +02:00
|
|
|
var renderIndex = (req:Request, res:Response) => {
|
|
|
|
res.render(_path.resolve(__dirname, './../../frontend/index.ejs'), res.tpl);
|
2016-03-19 17:31:42 +01:00
|
|
|
};
|
2016-05-09 17:04:56 +02:00
|
|
|
|
2016-05-16 11:03:11 +02:00
|
|
|
this.app.get(['/', '/login', "/gallery*", "/admin", "/search*"], renderIndex);
|
2016-03-19 17:31:42 +01:00
|
|
|
|
2016-03-18 21:36:58 +01:00
|
|
|
|
|
|
|
}
|
2016-05-09 17:04:56 +02:00
|
|
|
|
2016-03-18 21:36:58 +01:00
|
|
|
}
|