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

Remove HTTP2

parent 67f6cf71
......@@ -8,6 +8,12 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
Nothing yet.
## [3.0.0] - 2019-03-05
### Removed
- HTTP2 support (HTTP2 is not useful for [Small Tech](https://ar.al/2019/03/04/small-technology/) as it simply further privileges servers. If you need HTTP2, [use v2.0.1]().)
## [2.0.1] - 2019-03-01
### Fixed
......
......@@ -19,7 +19,7 @@ npm i -g @ind.ie/https-server
https-server [folder-to-serve] [--port N]
```
All arguments are optional. By default, a secure HTTP1 server will be created to serve the current folder over port 443.
All arguments are optional. By default, a secure HTTPS server will be created to serve the current folder over port 443.
If you do not already have TLS certificates, they will be created for you automatically using [nodecert](https://source.ind.ie/hypha/tools/nodecert).
......@@ -28,7 +28,7 @@ All dependencies will be installed automatically for you if they do not exist if
### API
__https-server__ provides a `createServer` method that behaves like the built-in _https_ module’s `createServer` function so anywhere you use `https.createServer`, you can simply replace it with `httpsServer.createServer`. Similarly, there is also a `createSecureServer` method that mirrors the function in the _http2_ module.
__https-server__ provides a `createServer` method that behaves like the built-in _https_ module’s `createServer` function so anywhere you use `https.createServer`, you can simply replace it with `httpsServer.createServer`.
#### createServer([options], [requestListener])
......@@ -54,28 +54,6 @@ const server = httpsServer.createServer(options, app).listen(443, () => {
})
```
#### createSecureServer([options], [requestListener])
- __options__ _(object)___:__ see [http2.createSecureServer](https://nodejs.org/api/http2.html#http2_http2_createsecureserver_options_onrequesthandler). Populates the `cert` and `key` properties from the automatically-created [nodecert](https://source.ind.ie/hypha/tools/nodecert/) certificates and will overwrite them if they exist in the options object you pass in.
- __requestListener__ _(function)___:__ see [http2.createSecureServer](https://nodejs.org/api/http2.html#http2_http2_createsecureserver_options_onrequesthandler)
- ___Returns:___ [Http2SecureServer](https://nodejs.org/api/http2.html#http2_class_http2secureserver) instance, configured with locally-trusted certificates.
##### Example
```js
const httpsServer = require('https-server')
const express = require('express')
const options = {} // (optional) customise your server
const server = httpsServer.createSecureServer(options, app).listen(443, () => {
console.log(` 🎉 Serving on https://localhost (HTTP2)\n`)
})
```
#### serve([pathToServe], [callback], [port])
- __pathToServe__ _(string)___:__ the directory to serve using [Express](http://expressjs.com/).static.
......@@ -110,7 +88,6 @@ Please [let me know how/if it works](https://github.com/indie-mirror/https-serve
- Command-line app. ✔
- Easy integration with Express, etc. ✔
- HTTP2 support (API only). ✔
- To-do: Seamless switch to using ACME/Let’s Encrypt in production.
## Thanks
......
const https = require('https')
const http2 = require('http2')
const fs = require('fs')
const express = require('express')
const morgan = require('morgan')
......@@ -34,23 +33,6 @@ class HttpsServer {
}
// Returns and HTTP2 Http2SecureServer instance, the same as you would get with
// require('http2').createSecureServer() – configured with your nodecert certificates.
// If you do pass a key and cert, they will be overwritten. Also the allowHTTP1 flag
// of the created server is set to true.
createSecureServer (options = {}, requestListener = undefined) {
const defaultOptions = {
key: fs.readFileSync(path.join(nodecertDirectory, 'localhost-key.pem')),
cert: fs.readFileSync(path.join(nodecertDirectory, 'localhost.pem')),
allowHTTP1: true
}
Object.assign(options, defaultOptions)
return http2.createSecureServer(options, requestListener)
}
// Starts a static server serving the contents of the passed path at the passed port
// and returns the server.
serve(pathToServe = '.', callback = null, port = 443) {
......@@ -61,19 +43,6 @@ class HttpsServer {
callback = null
}
// Express does not support HTTP2 yet. Disabling this until support is added.
// Once it’s ready we will replace the port argument with and options object.
// ===================================================================================
// Can be called as serve(pathToServe, callback) also.
// if (typeof callback === 'object') {
// options = callback
// callback = null
// }
// const port = options.port || 443
// const isHTTP2 = options.http2 || false
// const serverCreationMethod = isHTTP2 ? this.createSecureServer : this.createServer
// ===================================================================================
const serverCreationMethod = this.createServer
this.ensureWeCanBindToPort(port, pathToServe)
......@@ -86,11 +55,7 @@ class HttpsServer {
if (serverPort !== 443) {
portSuffix = `:${serverPort}`
}
// let isHTTP2Note = ''
// if (isHTTP2) {
// isHTTP2Note = ' (HTTP2)'
// }
console.log(` 🎉 Serving ${pathToServe} on https://localhost${portSuffix}\n`) //${isHTTP2Note}\n`)
console.log(` 🎉 Serving ${pathToServe} on https://localhost${portSuffix}\n`)
}
}
......
{
"name": "@ind.ie/https-server",
"version": "2.0.1",
"version": "3.0.0",
"description": "HTTPS server that uses nodecert",
"main": "index.js",
"bin": "bin/https-server.js",
......
......@@ -37,20 +37,6 @@ test('create https server', t => {
})
test('create http2 server', t => {
t.plan(2)
const server = httpsServer.createSecureServer()
// http2 does not export the Http2SecureServer class so we cannot use instanceof to test here.
t.equal(server.constructor.name, 'Http2SecureServer', 'is Http2SecureServer')
server.listen(443, () => {
t.equal(server.address().port, 443, 'the requested port is set on Http2SecureServer')
t.end()
server.close()
})
})
test('static serve https', t => {
t.plan(3)
const server = httpsServer.serve('test/site', async () => {
......@@ -72,29 +58,3 @@ test('static serve https', t => {
server.close()
})
})
// For when Express/.static gets HTTPS support.
// test('static serve HTTP2', t => {
// t.plan(3)
// const server = httpsServer.serve('test/site', async () => {
// t.equal(server.constructor.name, 'Http2SecureServer', 'is Http2SecureServer')
// let response
// try {
// response = await secureGet('https://localhost/index.html')
// } catch (error) {
// console.log(error)
// process.exit(1)
// }
// t.equal(response.statusCode, 200, 'request succeeds')
// t.equal(response.body, indexHTML, 'index loads')
// t.end()
// server.close()
// }, {
// isHTTP2: true
// })
// })
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