diff --git a/src/server/index.ts b/src/server/index.ts index 2901e94..a55d8e6 100644 --- a/src/server/index.ts +++ b/src/server/index.ts @@ -7,6 +7,7 @@ import * as koaStatic from "koa-static" import * as mount from "koa-mount" import apiRouter from "./api" import { PORT, SECRET_KEY, GIT_COMMIT } from "./config"; +import { User } from "./db/index"; const app = new Koa @@ -28,8 +29,17 @@ const router = new Router router.use("/api", apiRouter.routes()) router.get("/*", async ctx => { + var user + if (ctx.session!.user) { + user = await User.findById(ctx.session!.user) + user = JSON.stringify(user).replace(/[\u0080-\uFFFF]/g, chr => { + return "\\u"+("0000"+chr.charCodeAt(0).toString(16)).substr(-4) + }) + user = new Buffer(user, "binary").toString("base64") + } ctx.render("index.pug", { - GIT_COMMIT + GIT_COMMIT, + user }) }) diff --git a/src/server/views/index.pug b/src/server/views/index.pug index 0e5fa07..cfae85a 100644 --- a/src/server/views/index.pug +++ b/src/server/views/index.pug @@ -1,8 +1,12 @@ doctype html html head - script(src="/assets/bundle.js?version="+GIT_COMMIT) meta(name="viewport",content="width=device-width") + if user + script window.USER=JSON.parse(atob("!{user}")) + else + script window.USER=undefined + script(src="/assets/bundle.js?version="+GIT_COMMIT) body app p ...あれ、もしかしてページが表示されてませんか?