JSPM

@awesomeorganization/session-handler

1.1.0
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • 0
  • Score
    100M100P100Q47240F
  • License MIT

[ESM] The session handler for Node.js according to rfc6265

Package Exports

  • @awesomeorganization/session-handler

Readme

session-handler

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