fastify get ip
To get the IP address of a client in Fastify, you can use the request.ip property. Here's an example:
const fastify = require('fastify')();
fastify.get('/', (request, reply) => {
const ip = request.ip;
reply.send(`Your IP address is: ${ip}`);
});
fastify.listen(3000, (err) => {
if (err) {
console.error(err);
process.exit(1);
}
console.log('Server is running on port 3000');
});
In this example, when a client makes a GET request to the root URL ("/"), the server retrieves the client's IP address using request.ip and sends it back as a response
原文地址: https://www.cveoy.top/t/topic/hHmt 著作权归作者所有。请勿转载和采集!