Currently, I am in the process of developing a middleware that is intended to assign the user's IP address based on the cloudflare header provided. This method has worked successfully on previous projects of mine, but now it seems to be encountering issues.
Upon attempting to access the application, an error message is displayed:
TypeError: Cannot set property ip of #<IncomingMessage> which has only a getter
at /media/chen/storage/development/urlshortener/index.ts:67:11
at Layer.handle [as handle_request] (/media/chen/storage/development/urlshortener/node_modules/express/lib/router/layer.js:95:5)
... (additional error details omitted for brevity)
app.use((req, res, next) => {
req.ip = req.header('cf-connecting-ip') || req.ip; // The problematic line mentioned in the error at Line 67
next()
})
If necessary, I can provide more of my code. The snippet above covers everything except for the app.listen
statement following the completion of setting up all routes, middlewares, and express configurations.
To clarify, I am utilizing Express version 4.17.1