Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,23 @@
'use strict'

const fp = require('fastify-plugin')
const { parseCookie: parse, stringifySetCookie } = require('cookie')

const { Signer, sign, unsign } = require('./signer')

// TODO: Use require(ESM) when Node.js 20 is nolonger supported or Fastify@6
let cookieModule = null
async function dynamicLoadCookie () {
if (cookieModule == null) {
cookieModule = await import('cookie')
}
}

function serialize (name, value, options) {
return stringifySetCookie(Object.assign({ name, value }, options))
return cookieModule.stringifySetCookie(Object.assign({ name, value }, options))
}

function parse (header, options) {
return cookieModule.parseCookie(header, options)
Comment on lines +19 to +20

@climba03003 climba03003 Jul 11, 2026

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The wrapper is required for module.exports.

}

const kReplySetCookies = Symbol('fastify.reply.setCookies')
Expand Down Expand Up @@ -167,7 +178,7 @@ function plugin (fastify, options, next) {
// disables cookie autoparsing, not the ability to set cookies on the reply.
fastify.addHook('onSend', fastifyCookieOnSendHandler)

next()
dynamicLoadCookie().then(next, next)

// ***************************
function parseCookie (cookieHeader) {
Expand Down
Loading