Skip to content

Commit

Permalink
feat: added instructions to enable IPv6 networking on application ser…
Browse files Browse the repository at this point in the history
…vers (#617)

* feat: added IPv6 private networking instructions

---------

Co-authored-by: Brody Over <10548119+brody192@users.noreply.github.com>
  • Loading branch information
nimish-ks and brody192 authored Nov 27, 2024
1 parent ba0a5e0 commit d666daa
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 5 deletions.
7 changes: 4 additions & 3 deletions src/docs/guides/fixing-common-errors.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,22 +93,23 @@ async function bootstrap() {
#### Node / Next

Next needs an additional flag to listen on `PORT`:

```bash
next start --port ${PORT-3000}
```

#### Python / Gunicorn

`gunicorn` listens on `0.0.0.0` and the `PORT` environment variable by default:

```bash
gunicorn main:app
```

There is no additional configuration necessary.

#### Python / Uvicorn

`uvicorn` needs additional configuration flags to listen on `0.0.0.0` and `PORT`:

```bash
uvicorn main:app --host 0.0.0.0 --port $PORT
```
Expand Down Expand Up @@ -139,4 +140,4 @@ When an HTTP client encounters a 301 Moved Permanently redirect, the client will

### Solution

Fortunately, the solution is simple: Ensure you are using HTTPS when calling your Railway-hosted services.
Fortunately, the solution is simple: Ensure you are using HTTPS when calling your Railway-hosted services.
66 changes: 64 additions & 2 deletions src/docs/guides/private-networking.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,13 @@ To communicate over the private network, there are some specific things to know

### Listen on IPv6

Since the private network is an IPv6 network, applications that will receive requests over the private network must be configured to listen on IPv6. On most web frameworks, you can do this via `::` and specifying the port(s) to which you want to bind.
Since the private network is an IPv6 only network, applications that will receive requests over the private network must be configured to listen on IPv6. On most web frameworks, you can do this by binding to the host `::`.

For example -
Some examples are below -

#### Node / Express

Listen on `::` to bind to both IPv4 and IPv6.

```javascript
const port = process.env.PORT || 3000;
Expand All @@ -29,6 +33,64 @@ app.listen(port, '::', () => {
});
```

#### Node / Nest

Listen on `::` to bind to both IPv4 and IPv6.

```javascript
const port = process.env.PORT || 3000;

async function bootstrap() {
await app.listen(port, '::');
}
```

#### Node / Next

Update your start command to bind to both IPv4 and IPv6.

```bash
next start --hostname :: --port ${PORT-3000}
```

Or if you are using a custom server, set `hostname` to `::` in the configuration object passed to the `next()` function.

```javascript
const port = process.env.PORT || 3000;

const app = next({
// ...
hostname: '::',
port: port
});
```

If neither of these options are viable, you can set a `HOSTNAME` [service variable](/guides/variables#service-variables) with the value `::` to listen on both IPv4 and IPv6.

#### Python / Gunicorn

Update your start command to bind to both IPv4 and IPv6.

```bash
gunicorn app:app --bind [::]:${PORT-3000}
```

#### Python / Hypercorn

Update your start command to bind to both IPv4 and IPv6.

```bash
hypercorn app:app --bind [::]:${PORT-3000}
```

#### Python / Uvicorn

Update your start command to bind to IPv6.

```bash
uvicorn app:app --host :: --port ${PORT-3000}
```

**Note:** If your application needs to be accessible over both private and public networks, your application server must support dual stack binding. Most servers handle this automatically when listening on `::`, but some, like Uvicorn, do not.

### Use Internal Hostname and Port
Expand Down

0 comments on commit d666daa

Please sign in to comment.