Skip to content

DocsRun your app

Requests and sockets

How a request reaches your app: HTTPS, the hostnames the app answers on, the visitor's address in one header, requests per replica, WebSocket and Socket.IO.

Every request to your app comes through the platform. It takes the HTTPS connection, finds the app behind the hostname, and hands the request to a replica over plain HTTP, with the visitor’s address in a header.

Every address of an app answers over HTTPS, with a certificate that is issued and renewed for you. A request over plain HTTP is sent to HTTPS. Your app serves plain HTTP on its port and never sees a certificate. The headers your app sends with its answer reach the visitor as the app sent them: a content security policy, CORS or cookie headers are yours to set; the platform adds none of its own and removes only its own routing header.

An app answers on its own addresses only: the platform URL and the domains you add. A request for any other hostname never reaches your code; the visitor sees a page that says there is no app at that address.

One of the addresses is the primary one. Once a domain of your own is primary, the platform URL and the other domains send visitors on to it, with the same path, unless you choose Serve the app directly for a domain. See The primary domain.

Every request reaches your app with the header X-Real-IP: the address that connected to the platform, one value, IPv4 or IPv6. It is there on plain requests and on the request that opens a WebSocket alike. A copy sent by the visitor is removed before the request reaches your app, so the header can be trusted.

// Express. The guide of your framework shows its own way.
const visitor = request.get('X-Real-IP');
  • Read this header and no other. request.ip and the like are not the visitor: without a proxy setting they hold the address the request was handed on from, and with one they read a list that every hop adds to, in which the visitor’s entry can move when what sits in front of your app changes. X-Real-IP keeps its meaning.
  • Rate limits and logs by address should be given this header. Most packages read request.ip unless told otherwise.
  • Behind a proxy or CDN of your own, the address that connected to the platform is the proxy’s. Behind the most widely used proxy, the platform reads the visitor’s address from the header that proxy sets, and X-Real-IP holds the visitor’s address, once the domain’s check has seen the domain behind that proxy. After you put a domain behind it, choose Check again in the domain’s row or wait up to an hour; until then X-Real-IP holds the proxy’s address. On the platform URL it is always the address that connected. Behind any other proxy, X-Real-IP holds one of your proxy’s addresses, and the visitor’s address is in the header your proxy adds. Trust that header only when X-Real-IP is one of your proxy’s addresses; proxies publish their address ranges. Anyone can call your app through its platform URL and write any header they like, but they cannot make X-Real-IP a proxy’s address. Simpler still: switch the platform URL off under Domains, so the app answers only on domains that go through the proxy. See Behind a proxy or CDN of your own.

A replica handles a number of requests at once; the number is set under Settings, Scaling as Concurrent requests per replica, and the size decides it when you leave it empty:

Size Requests at the same time
Starter 25
Small 50
Medium 100
Large 200

When every running replica is at that number, another replica starts, as far as your plan allows. A replica takes up to twice the number; after that it answers nothing more until a request ends. Lower the number if each request is heavy, raise it if requests are light and mostly wait. See Scaling.

A request for a sleeping app is held while a replica starts, and handed over once the app listens. The visitor waits for as long as your app takes to start. See Sleep and wake.

A WebSocket works on the platform URL and on your own domains, also behind a proxy or CDN of your own. There is nothing to switch on. Socket.IO works too. The visitor’s address is in X-Real-IP on the request that opens the socket, as on any other.

Four things to know:

  • Each open socket is one request at a time. It holds one of the places a replica has for requests for as long as it stays open. A replica at twice its number answers nothing more, not even a plain page. Set Concurrent requests per replica to the number of people you expect connected at once per replica, from 1 to 1000. When your package.json has a socket library (socket.io, ws and others), the dashboard says so next to the setting, and a new app starts with 250 instead of the figure of its size. An app that already exists is not changed: raise the number yourself.

  • A deployment, a restart or a change of settings closes every socket once. Let clients connect again by themselves; one that tries again is served within seconds. The Socket.IO client does this unless told otherwise.

  • With more than one replica, use WebSocket only. Socket.IO starts with long polling, and polling needs every request of a client to reach the same replica, which is not promised. Tell the client to skip it:

    const socket = io({ transports: ['websocket'] });
  • Replicas share nothing. A message sent to all sockets reaches the sockets of that replica only. For more, bring a store of your own that every replica connects to (Socket.IO has an adapter for that). The platform offers none.

An open socket keeps the app awake: an app that sleeps when idle stays up while a socket is open, and a socket that knocks wakes it. A socket that sends nothing stays open for minutes; a short message now and then is still good practice. What goes out over a socket is bandwidth, like any other data the app sends.