Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(node:8) [FSTDEP019] FastifyDeprecation #992

Open
suryalokhande opened this issue Feb 9, 2024 · 7 comments
Open

(node:8) [FSTDEP019] FastifyDeprecation #992

suryalokhande opened this issue Feb 9, 2024 · 7 comments

Comments

@suryalokhande
Copy link

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
Copy link
Member

Eomm commented Feb 10, 2024

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

@suryalokhande
Copy link
Author

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
Copy link
Member

It is possible to provide a
Minimum Reproducible Example?

Maybe that would help

@gramcha
Copy link

gramcha commented Mar 8, 2024

@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
Copy link

Uzlopak commented Mar 8, 2024

@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
Copy link
Author

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

@jsumners
Copy link
Member

fastify/fastify#5310

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants