1
0
mirror of https://github.com/byulmaru/quesdon synced 2024-11-27 14:28:04 +09:00

window.USERにユーザー情報をしまうように

This commit is contained in:
rinsuki 2017-12-12 23:26:26 +09:00
parent 66c709ca17
commit 7540d54958
2 changed files with 16 additions and 2 deletions

View File

@ -7,6 +7,7 @@ import * as koaStatic from "koa-static"
import * as mount from "koa-mount" import * as mount from "koa-mount"
import apiRouter from "./api" import apiRouter from "./api"
import { PORT, SECRET_KEY, GIT_COMMIT } from "./config"; import { PORT, SECRET_KEY, GIT_COMMIT } from "./config";
import { User } from "./db/index";
const app = new Koa const app = new Koa
@ -28,8 +29,17 @@ const router = new Router
router.use("/api", apiRouter.routes()) router.use("/api", apiRouter.routes())
router.get("/*", async ctx => { 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", { ctx.render("index.pug", {
GIT_COMMIT GIT_COMMIT,
user
}) })
}) })

View File

@ -1,8 +1,12 @@
doctype html doctype html
html html
head head
script(src="/assets/bundle.js?version="+GIT_COMMIT)
meta(name="viewport",content="width=device-width") 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 body
app app
p ...あれ、もしかしてページが表示されてませんか? p ...あれ、もしかしてページが表示されてませんか?