1
0
mirror of https://github.com/xuthus83/pigallery2.git synced 2025-01-14 14:43:17 +08:00
pigallery2/backend/routes/PublicRouter.ts

45 lines
1.5 KiB
TypeScript
Raw Normal View History

2016-05-09 17:04:56 +02:00
import * as _express from "express";
import {NextFunction, Request, Response} from "express";
2016-05-09 17:04:56 +02:00
import * as _path from "path";
import {Utils} from "../../common/Utils";
2017-06-04 15:25:08 +02:00
import {Config} from "../../common/config/private/Config";
2017-07-03 19:17:49 +02:00
import {ProjectPath} from "../ProjectPath";
2017-07-13 23:39:09 +02:00
import {AuthenticationMWs} from "../middlewares/user/AuthenticationMWs";
2016-05-09 17:04:56 +02:00
export class PublicRouter {
2017-06-04 15:25:08 +02:00
public static route(app) {
2017-07-13 23:39:09 +02:00
const renderIndex = (req: Request, res: Response) => {
2017-07-28 00:04:19 +02:00
res.sendFile(_path.resolve(ProjectPath.FrontendFolder, 'index.html'), {maxAge: 31536000});
2017-07-13 23:39:09 +02:00
};
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;
}
res.tpl.clientConfig = Config.Client;
return next();
});
2016-05-09 17:04:56 +02:00
app.get('/config_inject.js', (req: Request, res: Response) => {
2017-07-28 00:04:19 +02:00
res.render(_path.resolve(ProjectPath.FrontendFolder, 'config_inject.ejs'), res.tpl);
});
2017-07-13 23:39:09 +02:00
app.get(['/', '/login', "/gallery*", "/share*", "/admin", "/search*"],
AuthenticationMWs.tryAuthenticate,
renderIndex
);
2017-07-28 00:04:19 +02:00
app.use(_express.static(ProjectPath.FrontendFolder, {maxAge: 31536000}));
// app.use('/node_modules', _express.static(_path.resolve(__dirname, './../../node_modules')));
// app.use('/common', _express.static(_path.resolve(__dirname, './../../common')));
}
2016-05-09 17:04:56 +02:00
}