fly-client-ip on an expressJS app using a custom cert

Hello, how would I be able to allow fly-client-ip passthrough on my express-js app?
I’ve tried proxy_proto but this causes my application to refuse connections (I’ve included the error below)

[error] could not proxy TCP data to/from instance: failed to copy (direction=client->server, error=Transport endpoint is not connected (os error 107))

Im using express but I am open to using other libraries, I would heavily prefer to stick to Javascript and it is important for me to be able to handle TLS on my own

  internal_port = 3000
  protocol = "tcp"
  processes = ['app']
  force_https = true
    port = 443

  size = 'shared-cpu-1x'

Here is the JS code (doesn’t include routes obviously)

const express = require('express');
const app = express();
const https = require('https');
app.set('trust proxy', true);
app.engine('html', require('ejs').renderFile);

  app.set('trust proxy', true);
//setting privatekey and certificate isn't included
const credentials = {
  key: privateKey,
  cert: certificate
  const httpsServer = https.createServer(credentials, app);
  const PORT = process.env.PORT || 3000;
httpsServer.listen(PORT, () => {
    console.log(`Server is listening on port ${PORT}`);

You would need to use a JS library that can speak the proxy protocol, or run a load balancer like nginx or haproxy that will handle the proxy protocol and TLS.

Thank you, I tried using a js library to handle this but it wasn’t working. I went the nginx route and its working as expected.

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.