Commit 628c9950 authored by Aral Balkan's avatar Aral Balkan

Add deprecation warnings

  - @ind.ie/https-server is now @ind.ie/web-server
parent 43c5081f
# HTTPS Server
HTTPS Server is a secure [Small Tech](https://ar.al/2019/03/04/small-technology/) personal web server for seamless development and live use.
## WARNING: This module has been deprecated, do not use.
HTTP Server uses [nodecert](https://source.ind.ie/hypha/tools/nodecert) for seamless locally-trusted TLS certificate provisioning and use during development and [ACME TLS](https://source.ind.ie/hypha/tools/acme-tls) for seamless globally-trusted [Let’s Encrypt](https://letsencrypt.org/) TLS certificate provisioning and use on live environments.
HTTPS Server has been renamed to [Indie Web Server](https://source.ind.ie/hypha/tools/web-server) and moved to the [@ind.ie/web-server](https://www.npmjs.com/package/@ind.ie/web-server) npm module.
__Please install the latest version of Indie Web Server instead of using this module.__
## Install
## Migration instructions
```sh
npm i -g @ind.ie/https-server
```
1. Remove https-server from global npm packages:
## Use
```shell
npm uninstall -g @ind.ie/https-server
```
### Command-line
2. Remove https-server from your local (if you were using the API):
Start serving the current directory at https://localhost:
```shell
npm uninstall @ind.ie/https-server
```
```shell
$ https-server
```
3. Install Indie Web Server as a global npm package and use the `web-server` command in Terminal:
Start serving the _site_ directory at your hostname:
```shell
npm i -g @ind.ie/web-server
web-server
```
4. Install Indie Web Server into your project to use the API:
```shell
$ https-server site --global
```
```shell
npm i @ind.ie/web-server
```
And in your app:
```js
const webServer = require('@ind.ie/web-server')
webServer.serve()
```
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]
```
All command-line arguments are optional. By default, an HTTPS server with locally-trusted certificates will be created for you 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).
All dependencies are installed automatically for you if they do not exist if you have apt, pacman, or yum (untested) on Linux or if you have [Homebrew](https://brew.sh/) or [MacPorts](https://www.macports.org/) (untested) on macOS.
If you specify the `--global` flag, globally-trusted Let’s Encrypt TLS certificates are automatically provisioned for you using ACME-TLS the first time you hit your hostname. The hostname for the certificates is automatically set from the hostname of your system (and the _www._ subdomain is also automatically provisioned).
### API
HTTPS Server’s `createServer` method behaves like the built-in _https_ module’s `createServer` function. Anywhere you use `https.createServer`, you can simply replace it with `httpsServer.createServer`.
#### createServer([options], [requestListener])
- __options__ _(object)___:__ see [https.createServer](https://nodejs.org/api/https.html#https_https_createserver_options_requestlistener). Populates the `cert` and `key` properties from the automatically-created [nodecert](https://source.ind.ie/hypha/tools/nodecert/) or Let’s Encrypt certificates and will overwrite them if they exist in the options object you pass in. If your options has `options.global = true` set, globally-trusted TLS certificates are obtained from Let’s Encrypt using ACME TLS.
- __requestListener__ _(function)___:__ see [https.createServer](https://nodejs.org/api/https.html#https_https_createserver_options_requestlistener). If you don’t pass a request listener, HTTPS Server will use its default one.
__Returns:__ [https.Server](https://nodejs.org/api/https.html#https_class_https_server) instance, configured with either locally-trusted certificates via nodecert or globally-trusted ones from Let’s Encrypt.
##### Example
```js
const httpsServer = require('https-server')
const express = require('express')
const app = express()
app.use(express.static('.'))
const options = {} // to use globally-trusted certificates instead, set this to {global: true}
const server = httpsServer.createServer(options, app).listen(443, () => {
console.log(` 🎉 Serving on https://localhost\n`)
})
```
#### serve([options])
Options is an optional parameter object that may contain the following properties, all optional:
- __path__ _(string)___:__ the directory to serve using [Express](http://expressjs.com/).static.
- __callback__ _(function)___:__ a function to be called when the server is ready. If you do not specify a callback, you can specify the port as the second argument.
- __port__ _(number)___:__ the port to serve on. Defaults to 443. (On Linux, privileges to bind to the port are automatically obtained for you.)
- __global__ _(boolean)___:__ if true, globally-trusted Let’s Encrypt certificates will be provisioned (if necesary) and used via ACME TLS. If false (default), locally-trusted certificates will be provisioned (if necesary) and used using nodecert.
__Returns:__ [https.Server](https://nodejs.org/api/https.html#https_class_https_server) instance, configured with either locally or globally-trusted certificates.
##### Example
Using locally-trusted TLS certificates:
```js
const httpsServer = require('https-server')
// Serve the current directory over https://localhost
const server = httpsServer.serve()
```
Using globally-trusted TLS certificates:
```js
const httpsServer = require('https-server')
// Serve the current directory over https://localhost
const server = httpsServer.serve({global: true})
```
## Help wanted
I can use your help to test HTTPS Server on the following platform/package manager combinations:
- Linux with yum
- macOS with MacPorts
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
* [thagoat](https://github.com/thagoat) for confirming that [installation works on Arch Linux with Pacman](https://github.com/indie-mirror/https-server/issues/1).
* [Tim Knip](https://github.com/timknip) for confirming that [the module works with 64-bit Windows](https://github.com/indie-mirror/https-server/issues/2) with the following behaviour: “Install pops up a windows dialog to allow adding the cert.”
* [Run Rabbit Run](https://hackers.town/@nobody) for [the following information](https://hackers.town/@nobody/101670447262172957) on 64-bit Windows: “Win64: works with the windows cert install popup on server launch. Chrome and ie are ok with the site then. FF 65 still throws the cert warning even after restarting.”
For for further instructions, please see the [Indie Web Server documentation](https://source.ind.ie/hypha/tools/web-server/blob/master/README.md) project.
\ No newline at end of file
......@@ -4,6 +4,11 @@ const path = require('path')
var ansi = require('ansi-escape-sequences')
const httpsServer = require('../index.js')
function displayDeprecationWarning() {
const deprecationNotice = `\n${clr(' WARNING: This module is deprecated. Do not use.', ['red', 'bg-white'])}\n${clr(httpsServer.deprecationNotice(), 'yellow')}`
console.log(deprecationNotice)
}
const arguments = require('minimist')(process.argv.slice(2))
if (arguments._.length > 2 || arguments.help === true) {
......@@ -24,12 +29,16 @@ if (arguments._.length > 2 || arguments.help === true) {
${usageVersionOption}\t\t\tDisplay the version.
`.replace(/\n$/, '').replace(/^\n/, '')
displayDeprecationWarning()
console.log(usage)
process.exit()
}
if (arguments.version !== undefined) {
const version = JSON.parse(fs.readFileSync(path.join(__dirname, '../package.json'), 'utf-8')).version
displayDeprecationWarning()
console.log(` https-server v${version}\n`)
process.exit()
}
......@@ -54,10 +63,14 @@ if (arguments.global !== undefined) {
}
if (!fs.existsSync(pathToServe)) {
displayDeprecationWarning()
console.log(` 🤔 Error: could not find path ${pathToServe}\n`)
process.exit(1)
}
displayDeprecationWarning()
// Start the server.
httpsServer.serve({
path: pathToServe,
......
......@@ -43,17 +43,24 @@ class HttpsServer {
serve (options) {
// The options parameter object and all supported properties on the options parameter
// object are optional. Check and populate the defaults.
const self = this
if (options === undefined) options = {}
const pathToServe = typeof options.path === 'string' ? options.path : '.'
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 () {
//
// Callback.
//
const serverPort = this.address().port
let portSuffix = ''
if (serverPort !== 443) {
portSuffix = `:${serverPort}`
}
const location = global ? os.hostname() : `localhost${portSuffix}`
self.displayDeprecationWarning()
console.log(` 🎉 Serving ${pathToServe} on https://${location}\n`)
}
......@@ -85,6 +92,17 @@ class HttpsServer {
return server
}
// This module is deprecated. It has been moved to @ind.ie/web-server.
deprecationNotice () {
return '\nHTTPS Server has been renamed to Indie Web Server and moved to @ind.ie/web-server. Please install the latest version of Indie Web Server instead of using this module.\n'
}
displayDeprecationWarning() {
const deprecationWarning = `\nWARNING: THIS MODULE IS DEPRECATED – DO NOT USE.\n${this.deprecationNotice()}`
console.log(deprecationWarning)
}
//
// Private.
//
......
{
"name": "@ind.ie/https-server",
"version": "5.1.0",
"description": "A secure Small Tech personal web server for seamless development and live use.",
"version": "5.1.1",
"description": "Deprecated, please use @ind.ie/web-server instead.",
"main": "index.js",
"bin": "bin/https-server.js",
"scripts": {
......@@ -10,7 +10,7 @@
},
"repository": {
"type": "git",
"url": "git@source.ind.ie:hypha/tools/https-server.git"
"url": "git@source.ind.ie:hypha/tools/web-server.git"
},
"author": {
"name": "Aral Balkan",
......
......@@ -5,6 +5,7 @@ const https = require('https')
const indexHTML = "<!DOCTYPE html><html lang='en'><head><title>Test</title><body><h1>Test</h1></body></html>"
httpsServer.displayDeprecationWarning()
async function secureGet (url) {
return new Promise((resolve, reject) => {
......@@ -25,6 +26,9 @@ async function secureGet (url) {
test('create https server', t => {
httpsServer.displayDeprecationWarning()
t.plan(2)
const server = httpsServer.createServer()
t.ok(server instanceof https.Server, 'is https.Server')
......@@ -38,6 +42,9 @@ test('create https server', t => {
test('static serve https', t => {
httpsServer.displayDeprecationWarning()
t.plan(3)
const server = httpsServer.serve({path: 'test/site', callback: async () => {
......
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