Verified Commit efc7ba95 authored by Aral Balkan's avatar Aral Balkan
Browse files

Fix bugs; both local and globally-trusted tls servers now working

parent 36047d22
......@@ -11,11 +11,26 @@ HTTP Server uses [nodecert](https://source.ind.ie/hypha/tools/nodecert) for seam
npm i -g @ind.ie/https-server
```
## Use
### Command-line
Start serving the current directory at https://localhost:
```shell
$ https-server
```
Start serving the _site_ directory at your hostname:
```shell
$ https-server site --global
```
For example, if you run the command on a connected server that has the ar.al domain pointing to it and `ar.al` set in _/etc/hostname_ (on Unix/Linux), you will be able to access the site at https://ar.al. The first time you access it, it will take a little longer to load as your Let’s Encrypt certificates are being automatically provisioned.
#### Syntax
```sh
https-server [folder-to-serve] [--port N] [--global] [--version]
```
......@@ -100,6 +115,8 @@ I can use your help to test HTTPS Server on the following platform/package manag
Please [let me know how/if it works](https://github.com/indie-mirror/https-server/issues). Thank you!
Also, automatic hostname detection has not been implemented for Windows and so globally-trusted certificates will fail on that platform. If you get to it before I do, [I would appreciate a pull request](https://github.com/indie-mirror/https-server/pulls).
## Thanks
......
......@@ -50,7 +50,7 @@ if (arguments.port !== undefined) {
// If global is specified, use it.
let global = false
if (arguments.global !== undefined) {
global = arguments.global === 'true'
global = arguments.global === true
}
if (!fs.existsSync(pathToServe)) {
......@@ -60,7 +60,7 @@ if (!fs.existsSync(pathToServe)) {
// Start the server.
httpsServer.serve({
path: pathToServer,
path: pathToServe,
port,
global
})
......
......@@ -52,9 +52,17 @@ class HttpsServer {
// object are optional. Check and populate the defaults.
if (options === undefined) options = {}
const pathToServe = typeof options.path === 'string' ? options.path : '.'
const callback = typeof options.callback === 'function' ? options.callback : null
const port = typeof options.port === 'number' ? options.port : 443
const global = typeof options.global === 'boolean' ? options.global : false
const callback = typeof options.callback === 'function' ? options.callback : function () {
const serverPort = this.address().port
let portSuffix = ''
if (serverPort !== 443) {
portSuffix = `:${serverPort}`
}
const location = global ? os.hostname() : `localhost${portSuffix}`
console.log(` 🎉 Serving ${pathToServe} on https://${location}\n`)
}
// Check for a valid port range
// (port above 49,151 are ephemeral ports. See https://en.wikipedia.org/wiki/List_of_TCP_and_UDP_port_numbers#Dynamic,_private_or_ephemeral_ports)
......@@ -68,19 +76,6 @@ class HttpsServer {
// in dropping this requirement soon (macOS just did in Mojave).
this._ensureWeCanBindToPort(port, pathToServe)
// If a callback isn’t provided, fallback to a default one that gives a status update.
if (callback === null) {
callback = function () {
const serverPort = this.address().port
let portSuffix = ''
if (serverPort !== 443) {
portSuffix = `:${serverPort}`
}
const location = email === undefined ? `localhost${portSuffix}` : os.hostname()
console.log(` 🎉 Serving ${pathToServe} on https://${location}\n`)
}
}
// Create an express server to serve the path using Morgan for logging.
const app = express()
app.use(morgan('tiny'))
......@@ -132,7 +127,7 @@ class HttpsServer {
agreeTos: true,
telemetry: false,
communityMember: false,
// email: ' ',
email: ' ',
})
// Create an HTTP server to handle redirects for the Let’s Encrypt ACME HTTP-01 challenge method that we use.
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment