visionmedia/express — Issue #899: app.address() crashes in HTTP + HTTPS mode
Author: thatmarvin
Created: 2011-11-23 01:21:23+00:00
State: open

I'm trying to run both HTTP and HTTPS servers as described in [this gist](https://gist.github.com/1051583).

It all runs fine until it hits the last auto-generated `console.log` which invokes `app.address().port`, throwing the following error:

```
TypeError: Bad file descriptor argument
at HTTPServer.address (net.js:1129:10)
at Object. (/Users/mtam/test/app.js:52:67)
at Module._compile (module.js:411:26)
at Object..js (module.js:417:10)
at Module.load (module.js:343:31)
at Function._load (module.js:302:12)
at Array. (module.js:430:10)
at EventEmitter._tickCallback (node.js:126:26)
```

The servers run perfectly if I remove that line.

A couple things:
1. Is `app.address()` documented somewhere?
2. What's a good way to check if an incoming request is HTTP or HTTPS? I wanted to use `app.address().port`, but that crashed; I see some HTTPS-specific variables in `req`, but depending on that seems unreliable.

Thanks!