Closed Xa3lis closed 7 months ago
Thanks for reporting.
Ultimately Bun does not implement all Node.js APIs. It's not a clean drop-in replacement for Node.js (despite their claims). Please refer to the Bun Discord or Issue Tracker for such questions.
Prerequisites
Fastify version
4.24.3
Plugin version
4.5.1
Node.js version
x
Operating system
macOS
Operating system version (i.e. 20.04, 11.3, 10)
14.0
Description
Hello
I've encountered an error with Bun v1.0.23 in the extractPluginName function
The logs format in node and in Bun are sometimes not the same, and for the Fastify Session plugin it's shown as "" in the logs
I've made it to work by changing
return m ? m[1].split(/[/\\]/).slice(-1)[0].match(fileNamePattern)[1] : 'anonymous'
to
return m ? m[1]?.split(/[/\\]/)?.slice(-1)?.[0]?.match(fileNamePattern)?.[1] : 'anonymous'
If you have another idea, it could be even better, but aside from that everything is working well with Bun
Steps to Reproduce
Using Nest.JS
import { Authenticator } from '@fastify/passport' import fastifySession from '@fastify/session'
const createFileStore = await import('session-file-store') store = new (createFileStore.default(fastifySession))({})
await app.register(fastifyCookie) await app.register( fastifySession, { store, secret: "SECRET", saveUninitialized: false, cookieName: 'COOKIE_NAME', cookie: { maxAge: 60 60 1000, httpOnly: true, secure: env.NODE_ENV === 'production', }, }, )
fastifyPassport.registerUserSerializer(async user => user)
fastifyPassport.registerUserDeserializer(async payload => payload)
await app.register(fastifyPassport.initialize()) await app.register(fastifyPassport.secureSession())
const fastifyInstance: FastifyInstance = app.getHttpAdapter().getInstance() fastifyInstance .decorateReply('setHeader', async function (name: string, value: unknown): Promise {
return await this.header(name, value)
})
.decorateReply('end', async function (): Promise {
return await this.send()
})
Expected Behavior
Use nullish coalescing to avoid some edge cases