forked from fastify/session
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutil.js
More file actions
36 lines (31 loc) · 1.12 KB
/
Copy pathutil.js
File metadata and controls
36 lines (31 loc) · 1.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
'use strict'
const Fastify = require('fastify')
const fastifyCookie = require('@fastify/cookie')
const fastifySession = require('../lib/fastifySession')
const TestStore = require('./TestStore')
const DEFAULT_SECRET = 'cNaoPYAwF60HZJzkcNaoPYAwF60HZJzk'
const DEFAULT_OPTIONS = { secret: DEFAULT_SECRET }
const DEFAULT_SESSION_ID = 'Qk_XT2K7-clT-x1tVvoY6tIQ83iP72KN'
const DEFAULT_ENCRYPTED_SESSION_ID = `${DEFAULT_SESSION_ID}.B7fUDYXU9fXF9pNuL3qm4NVmSduLJ6kzCOPh5JhHGoE`
const DEFAULT_COOKIE_VALUE = `sessionId=${DEFAULT_ENCRYPTED_SESSION_ID};`
const DEFAULT_COOKIE = `${DEFAULT_COOKIE_VALUE}; Path=/; HttpOnly; Secure`
async function buildFastify (handler, sessionOptions, plugin) {
const fastify = Fastify()
await fastify.register(fastifyCookie)
if (plugin) {
await fastify.register(plugin)
}
await fastify.register(fastifySession, { store: new TestStore(), ...sessionOptions })
fastify.get('/', handler)
await fastify.listen({ port: 0 })
return fastify
}
module.exports = {
buildFastify,
DEFAULT_SECRET,
DEFAULT_OPTIONS,
DEFAULT_SESSION_ID,
DEFAULT_ENCRYPTED_SESSION_ID,
DEFAULT_COOKIE_VALUE,
DEFAULT_COOKIE
}