+ cookie session

This commit is contained in:
tmshv committed 2017-05-31 20:42:36 +03:00
1 parent 0480e6e980
commit c3fb349043
2 files changed
+20

No files matched your search

+1
View File
@@ -48,6 +48,7 @@
"koa-mount": "^2.0.0",
"koa-query": "0.0.2",
"koa-route": "^3.1.0",
"koa-session": "^4.0.0",
"koa-static": "^3.0.0",
"moment": "^2.18.1",
"mongodb": "^2.1.14",
+19
View File
@@ -9,6 +9,7 @@ import etag from 'koa-etag'
import helmet from 'koa-helmet'
import mount from 'koa-mount'
import cookie from 'koa-cookie'
import session from 'koa-session'
import bodyParser from 'koa-bodyparser'
import apiV1 from 'hudozka-api-v1'
@@ -44,10 +45,19 @@ const collectiveOrder = [
'nv-andreeva',
]
const sessionConfig = {
key: 'sid', /** (string) cookie key */
maxAge: 86400000, /** (number) maxAge in ms */
overwrite: false, /** (boolean) can overwrite or not */
httpOnly: false, /** (boolean) httpOnly or not */
signed: true, /** (boolean) signed or not */
}
export default function (store) {
const $ = convert
const app = new Koa()
app.keys = ['1234']
app.proxy = true
app.use(bodyParser({
@@ -57,6 +67,7 @@ export default function (store) {
}))
app.use(logger())
app.use(apis(store))
app.use(convert(session(sessionConfig, app)))
app.use(cookie())
app.use($(conditional()))
app.use($(etag()))
@@ -65,6 +76,14 @@ export default function (store) {
app.use($(helmet()))
app.use(queryObject())
app.use(async (ctx, next) => {
if (ctx.session.isNew) {
ctx.session.startDate = new Date()
}
await next()
})
app.use(error.notFound(config.view404))
app.use(sitemap())