+ cookie session
This commit is contained in:
1 parent
0480e6e980
commit
c3fb349043
2 files changed
+20
No files matched your search
@@ -48,6 +48,7 @@
|
|||||||
"koa-mount": "^2.0.0",
|
"koa-mount": "^2.0.0",
|
||||||
"koa-query": "0.0.2",
|
"koa-query": "0.0.2",
|
||||||
"koa-route": "^3.1.0",
|
"koa-route": "^3.1.0",
|
||||||
|
"koa-session": "^4.0.0",
|
||||||
"koa-static": "^3.0.0",
|
"koa-static": "^3.0.0",
|
||||||
"moment": "^2.18.1",
|
"moment": "^2.18.1",
|
||||||
"mongodb": "^2.1.14",
|
"mongodb": "^2.1.14",
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import etag from 'koa-etag'
|
|||||||
import helmet from 'koa-helmet'
|
import helmet from 'koa-helmet'
|
||||||
import mount from 'koa-mount'
|
import mount from 'koa-mount'
|
||||||
import cookie from 'koa-cookie'
|
import cookie from 'koa-cookie'
|
||||||
|
import session from 'koa-session'
|
||||||
import bodyParser from 'koa-bodyparser'
|
import bodyParser from 'koa-bodyparser'
|
||||||
|
|
||||||
import apiV1 from 'hudozka-api-v1'
|
import apiV1 from 'hudozka-api-v1'
|
||||||
@@ -44,10 +45,19 @@ const collectiveOrder = [
|
|||||||
'nv-andreeva',
|
'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) {
|
export default function (store) {
|
||||||
const $ = convert
|
const $ = convert
|
||||||
|
|
||||||
const app = new Koa()
|
const app = new Koa()
|
||||||
|
app.keys = ['1234']
|
||||||
app.proxy = true
|
app.proxy = true
|
||||||
|
|
||||||
app.use(bodyParser({
|
app.use(bodyParser({
|
||||||
@@ -57,6 +67,7 @@ export default function (store) {
|
|||||||
}))
|
}))
|
||||||
app.use(logger())
|
app.use(logger())
|
||||||
app.use(apis(store))
|
app.use(apis(store))
|
||||||
|
app.use(convert(session(sessionConfig, app)))
|
||||||
app.use(cookie())
|
app.use(cookie())
|
||||||
app.use($(conditional()))
|
app.use($(conditional()))
|
||||||
app.use($(etag()))
|
app.use($(etag()))
|
||||||
@@ -65,6 +76,14 @@ export default function (store) {
|
|||||||
app.use($(helmet()))
|
app.use($(helmet()))
|
||||||
app.use(queryObject())
|
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(error.notFound(config.view404))
|
||||||
app.use(sitemap())
|
app.use(sitemap())
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user