1.1.0 • Published 3 years ago

@awesomeorganization/session-handler v1.1.0

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

session-handler

:boom: ESM The session handler for Node.js according to rfc6265


npm npm npm npm npm npm


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()