fastify / help

Need help with Fastify? File an Issue here.
https://www.fastify.io/
64 stars 8 forks source link

(node:8) [FSTDEP019] FastifyDeprecation #992

Open suryalokhande opened 5 months ago

suryalokhande commented 5 months ago

Seeing deprecation issues as pointed by FSTDEP019 https://fastify.dev/docs/latest/Reference/Warnings/#FSTDEP019 (node:8) [FSTDEP019] FastifyDeprecation

here message (node:8) [FSTDEP019] FastifyDeprecation: reply.context property access is deprecated. Please use "reply.routeOptions.config" or "reply.routeOptions.schema" instead for accessing Route settings. The "reply.context" will be removed in fastify@5.

Context

fastify current version - 4.26.0

Tried disabling by these but no luck. passing the --no-warnings flag to the node process setting 'no-warnings' in the NODE_OPTIONS environment variable

any suggestion how to over come these deprecated messages ?

Eomm commented 5 months ago

Did you search for .context in your codebase? Is there any fastify's plugin that is using it?

suryalokhande commented 4 months ago

Thank you Eomm,

Can see reference like : reply?.context?.schema?.description in cade base (around 7hits) but i don't see any .context in register function.

Any suggestion how to over come these deprecated messages ?

(node:8) [FSTDEP019] FastifyDeprecation: reply.context property access is deprecated. Please use "reply.routeOptions.config" or "reply.routeOptions.schema" instead for accessing Route settings. The "reply.context" will be removed in fastify@5.

as we are seeing lot of such error messages, intern this causing huge logs for my server.

metcoder95 commented 4 months ago

It is possible to provide a Minimum Reproducible Example?

Maybe that would help

gramcha commented 4 months ago

@metcoder95 FYR

log

mdm-doer > 2024-03-08T03:27:32.850Z [info]: Started <8223f4e9-ef4a-4ff5-9fb1-f511806fd8c6>: GET /cl-doer/api/life-line                          │
mdm-doer > 2024-03-08T03:27:32.851Z [info]: IP <8223f4e9-ef4a-4ff5-9fb1-f511806fd8c6>: 10.10.17.6 User-Agent : Other 0.0.0 / Other 0.0.0        │
mdm-doer > /cl-doer/api/life-line path                                                                                                          │
mdm-doer > 2024-03-08T03:27:32.866Z [info]: Ended <8223f4e9-ef4a-4ff5-9fb1-f511806fd8c6>: GET /cl-doer/api/life-line 200 - 15.773136138916016   │
mdm-doer > (node:96) [FSTDEP019] FastifyDeprecation: reply.context property access is deprecated. Please use "reply.routeOptions.config" or     │

respective controller code of that life-line API

const { HealthChecker } = require('./life-line');

class LifeLineController {
  static async perform(request, reply) {
    const result = await HealthChecker.perform();
    if (result?.isDiskHealthy) {
        reply.code(200);
    } else {
        reply.code(503);
    }
    reply.header('Content-Type', 'application/json; charset=utf-8');
    reply.send(result);
  }
}

module.exports = LifeLineController;

hook for request logger.

const fp = require('fastify-plugin');
const { v4: uuid } = require('uuid');
const useragent = require('useragent');

module.exports = fp(async (fastify, opts) => {
  const apiRequestId = uuid();
  fastify.addHook('onRequest', (request, reply, done) => {
    const requestIp = request.ip;
    const userAgent = useragent.parse(request.headers['user-agent']).toString();
    logger.info(`Started <${apiRequestId}>: ${request.method} ${request.url}`);
    logger.info(`IP <${apiRequestId}>: ${requestIp} User-Agent : ${userAgent}`);
    done();
  });
  fastify.addHook('preHandler', async (request) => {
    console.log(request.url, 'path');
    if (['PUT', 'POST', 'PATCH'].includes(request.method) && !request.url.includes('cl-auth')) {
      logger.info(`Ended <${apiRequestId}>: ${JSON.stringify(request.body)}`);
    }
  });
  fastify.addHook('onResponse', (request, reply, done) => {
    const responseTime = reply.getResponseTime();
    logger.info(`Ended <${apiRequestId}>: ${request.method} ${request.url} ${reply.statusCode} - ${responseTime} ms`);
    done();
  });
  fastify.addHook('onError', async (request, reply, error) => {
    reply.code(500);
  })
});
Uzlopak commented 4 months ago

@gramcha

We are on GitHub and not on stackoverflow. Provide a link to a github repo with the mvce so that each maintainer doesnt need to rebuild your example.

suryalokhande commented 4 months ago

.context Thank you Eomm, nope, i don't see any reference of .context in my code base.

jsumners commented 4 months ago

https://github.com/fastify/fastify/pull/5310