2020-07-17 13:24:20 +03:00
|
|
|
import * as MW from "~/node_common/middleware";
|
2020-07-24 03:22:22 +03:00
|
|
|
import * as ViewerManager from "~/node_common/managers/viewer";
|
2020-07-22 08:53:29 +03:00
|
|
|
import * as Utilities from "~/node_common/utilities";
|
2020-07-17 13:24:20 +03:00
|
|
|
|
|
|
|
const initCORS = MW.init(MW.CORS);
|
2020-07-21 14:36:50 +03:00
|
|
|
const initAuth = MW.init(MW.RequireCookieAuthentication);
|
2020-07-17 13:24:20 +03:00
|
|
|
|
|
|
|
export default async (req, res) => {
|
|
|
|
initCORS(req, res);
|
2020-07-21 14:36:50 +03:00
|
|
|
initAuth(req, res);
|
2020-07-17 13:24:20 +03:00
|
|
|
|
2020-07-22 13:51:40 +03:00
|
|
|
const id = Utilities.getIdFromCookie(req);
|
|
|
|
if (!id) {
|
2020-07-22 08:53:29 +03:00
|
|
|
return res
|
|
|
|
.status(500)
|
2020-07-24 10:45:21 +03:00
|
|
|
.json({ decorator: "SERVER_HYDRATE_FAILURE", error: true });
|
2020-07-22 08:53:29 +03:00
|
|
|
}
|
|
|
|
|
2020-07-24 03:22:22 +03:00
|
|
|
const data = await ViewerManager.getById({ id });
|
2020-07-17 13:24:20 +03:00
|
|
|
|
|
|
|
return res
|
|
|
|
.status(200)
|
|
|
|
.send({ decorator: "SERVER_HYDRATE", success: true, data });
|
|
|
|
};
|