@awesomeorganization/session-handler
v1.1.0
Published
[ESM] The session handler for Node.js according to rfc6265
Downloads
6
Maintainers
Readme
session-handler
:boom: [ESM] The session handler for Node.js according to rfc6265
Example
Full example in /example
folder.
import { http } from '@awesomeorganization/servers'
import { sessionHandler } from '@awesomeorganization/session-handler'
const example = async () => {
const sessionMiddleware = await sessionHandler()
http({
listenOptions: {
host: '127.0.0.1',
port: 3000,
},
async onRequest(request, response) {
const { sessionId, storage } = await sessionMiddleware.handle({
request,
response,
})
const counter = storage.get('counter') ?? 0
storage.set('counter', counter + 1)
response.end(`Hi ${sessionId}! you have visited this page ${counter} times`)
},
})
// TRY
// http://127.0.0.1:3000/
}
example()