1.0.4 • Published 6 years ago
fast-store-knex v1.0.4
fast-store-knex
Session knex store for fastify and fastity-session
Save the session to the database with the knex
Requires
Instalation
npm i fast-store-knex
Usage
const fastify = require("fastify")()
// Connection
var knex = require("knex")({
client: 'mysql',
connection: {
host: '127.0.0.1',
user: 'root',
password: '',
database: 'test'
}
})
const Store = require("fast-store-knex")
fastify.register(require('fastify-cookie'))
fastify.register(require('fastify-session'), {
store: new Store(knex),
cookie: {
httpOnly: true,
secure: false,
},
secret: 'a secret with minimum length of 32 characters'
})
// Write session
fastify.get('/write', (request, reply) => {
request.session.text = "Hello world"
reply.send({
out: "fast !"
})
})
// Read session
fastify.get('/read', (request, reply) => {
reply.send({
out: "fast !",
text: request.session.text
})
})
fastify.listen(3000, err => {
if (!err) fastify.log.info(`server listening on ${fastify.server.address().port}`)
});