Skip to content

Feature Request: Ability to use the node:net library to talk to the container so that vendored client libraries for vendored services can be used. #67

@jschlesser

Description

@jschlesser

It would be helpful to be able to talk to the container from the DO using the node:net library so that vendored libs can be used to talk to non http services. I understand that in general workers are very http oriented and that there is some kind of proxy that tcpPort is talking to when code like this const conn = this.ctx.container.getTcpPort(8080).connect('10.0.0.1:8080'); is run.

My particular use case is the use of the mssql lib https://www.npmjs.com/package/mssql in a Durable Object to maintain a connection pool to a database that isn't supported by hyperdrive.

And in the Dockerfile something like this cloudflared access tcp --hostname sql-tunnel.mydomain.com --url localhost:1433 --service-token-id ${CF_ACCESS_CLIENT_ID} --service-token-secret ${CF_ACCESS_CLIENT_SECRET}

In my case the container would only have to run the client end of a cloudflared tunnel into my datacenter.

However, this feature handles a general pattern of talking to a service that runs TCP sockets on the Container or tunneled to a datacenter paired with a well known and battle tested client library purpose built for the service. It could be redis or mongodb or a datawarehouse or some other crazy thing.

It would make the DO code below possible:

const sql = require('mssql');
// gets some host and port information that is only good for talking to our container
const {host,port} = this.ctx.container.getTcpPort(1433).getAddressInfo()

const config = {
    user: process.env.DB_USER ,
    password: process.env.DB_PASSWORD,
    server: host,  // Container's internal cloudflared proxy
    port: port,
    database: process.env.DB_NAME,
    options: {
        encrypt: true,
        trustServerCertificate: true,
        enableArithAbort: true,
        connectionTimeout: 30000,
        requestTimeout: 30000
    }
};
try {
    pool = await sql.connect(config);
    console.log('✅ Connected to SQL Server through Cloudflare proxy');
    return true;
} catch (err) {
    console.error('❌ Failed to connect to SQL Server:', err.message);
    return false;
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions