forked from fastify/session
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathredis.js
More file actions
35 lines (27 loc) · 843 Bytes
/
Copy pathredis.js
File metadata and controls
35 lines (27 loc) · 843 Bytes
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
'use strict'
const Fastify = require('fastify')
const fastifySession = require('..')
const fastifyCookie = require('@fastify/cookie')
const Redis = require('ioredis')
const redisStoreFactory = require('connect-redis')
const fastify = Fastify()
const RedisStore = redisStoreFactory(fastifySession)
const store = new RedisStore({
client: new Redis({
enableAutoPipelining: true
})
})
fastify.register(fastifyCookie, {})
fastify.register(fastifySession, {
secret: 'cNaoPYAwF60HZJzkcNaoPYAwF60HZJzk',
cookie: { secure: false },
store
})
fastify.get('/', (request, reply) => {
reply
.send(request.cookies.sessionId)
})
const response = fastify.inject('/')
response.then(v => console.log(`
autocannon -p 10 -H "Cookie=${decodeURIComponent(v.headers['set-cookie'])}" http://127.0.0.1:3000`))
fastify.listen({ port: 3000 })