2016-05-09 23:04:56 +08:00
|
|
|
import * as _express from "express";
|
2016-04-10 00:06:29 +08:00
|
|
|
import {NextFunction, Request, Response} from "express";
|
2016-05-09 23:04:56 +08:00
|
|
|
import * as _path from "path";
|
|
|
|
import {Utils} from "../../common/Utils";
|
2017-06-04 21:25:08 +08:00
|
|
|
import {Config} from "../../common/config/private/Config";
|
2016-04-10 00:06:29 +08:00
|
|
|
|
2016-05-09 23:04:56 +08:00
|
|
|
export class PublicRouter {
|
2017-06-04 21:25:08 +08:00
|
|
|
|
|
|
|
public static route(app) {
|
|
|
|
app.use((req: Request, res: Response, next: NextFunction) => {
|
2016-04-10 00:06:29 +08:00
|
|
|
res.tpl = {};
|
|
|
|
|
|
|
|
res.tpl.user = null;
|
2016-05-09 23:04:56 +08:00
|
|
|
if (req.session.user) {
|
2016-04-10 00:06:29 +08:00
|
|
|
let user = Utils.clone(req.session.user);
|
|
|
|
delete user.password;
|
|
|
|
res.tpl.user = user;
|
|
|
|
}
|
2016-05-11 03:33:58 +08:00
|
|
|
res.tpl.clientConfig = Config.Client;
|
2016-04-10 00:06:29 +08:00
|
|
|
|
|
|
|
return next();
|
|
|
|
});
|
2016-05-09 23:04:56 +08:00
|
|
|
|
2017-06-04 21:25:08 +08:00
|
|
|
app.use(_express.static(_path.resolve(__dirname, './../../frontend')));
|
|
|
|
app.use('/node_modules', _express.static(_path.resolve(__dirname, './../../node_modules')));
|
|
|
|
app.use('/common', _express.static(_path.resolve(__dirname, './../../common')));
|
2016-03-20 00:31:42 +08:00
|
|
|
|
2016-12-27 06:36:38 +08:00
|
|
|
const renderIndex = (req: Request, res: Response) => {
|
2016-05-09 23:04:56 +08:00
|
|
|
res.render(_path.resolve(__dirname, './../../frontend/index.ejs'), res.tpl);
|
2016-03-20 00:31:42 +08:00
|
|
|
};
|
2016-05-09 23:04:56 +08:00
|
|
|
|
2017-06-04 21:25:08 +08:00
|
|
|
app.get(['/', '/login', "/gallery*", "/admin", "/search*"], renderIndex);
|
2016-03-20 00:31:42 +08:00
|
|
|
|
2016-03-19 04:36:58 +08:00
|
|
|
|
|
|
|
}
|
2016-05-09 23:04:56 +08:00
|
|
|
|
2016-03-19 04:36:58 +08:00
|
|
|
}
|