I'm trying to create a middleware that sets the user's IP to the cloudflare header it gives us, for the rest of the app. This used to work on my projects, but now for some reason, it doesn't.
When I try to navigate to the app, it gives me the following error:
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)
at trim_prefix (/media/chen/storage/development/urlshortener/node_modules/express/lib/router/index.js:317:13)
at /media/chen/storage/development/urlshortener/node_modules/express/lib/router/index.js:284:7
at Function.process_params (/media/chen/storage/development/urlshortener/node_modules/express/lib/router/index.js:335:12)
at next (/media/chen/storage/development/urlshortener/node_modules/express/lib/router/index.js:275:10)
at jsonParser (/media/chen/storage/development/urlshortener/node_modules/body-parser/lib/types/json.js:110:7)
at Layer.handle [as handle_request] (/media/chen/storage/development/urlshortener/node_modules/express/lib/router/layer.js:95:5)
at trim_prefix (/media/chen/storage/development/urlshortener/node_modules/express/lib/router/index.js:317:13)
at /media/chen/storage/development/urlshortener/node_modules/express/lib/router/index.js:284:7
app.use((req, res, next) => {
req.ip = req.header('cf-connecting-ip') || req.ip; // Line 67, which the error is mentioning
next()
})
If I should include the rest of my code, please tell me. This is all there is except app.listen
after the promise that all routes, middlewares, and express settings, are included in
I'm using Express 4.17.1