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

Complete name change

parent 45b07d6d
Pipeline #814 canceled with stages
......@@ -8,6 +8,18 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
Nothing yet.
## [6.0.0] – 2019-03-09
## Changed
- __Name:__ HTTPS Server is now called Indie Web Server.
- __NPM module:__ @ind.ie/https-server is now @ind.ie/web-server.
- __Source code repository:__ Now located at https://source.ind.ie/hypha/tools/web-server/.
## Added
- [Helmet](https://helmetjs.github.io/) for securing the Express app further.
## [5.1.0] - 2019-03-09
### Changed
......
......@@ -2,7 +2,7 @@
const fs = require('fs')
const path = require('path')
var ansi = require('ansi-escape-sequences')
const httpsServer = require('../index.js')
const webServer = require('../index.js')
const arguments = require('minimist')(process.argv.slice(2))
......@@ -16,7 +16,7 @@ if (arguments._.length > 2 || arguments.help === true) {
const usage = `
${clr('Usage:', 'underline')}
${clr('https-server', 'bold')} [${usageFolderToServe}] [${usagePortOption}] [${usageGlobalOption}] [${usageVersionOption}]
${clr('web-server', 'bold')} [${usageFolderToServe}] [${usagePortOption}] [${usageGlobalOption}] [${usageVersionOption}]
${usageFolderToServe}\t\tPath to the folder to serve (defaults to current folder).
${usagePortOption}\t\t\tThe port to start the server on (defaults to 443).
......@@ -29,8 +29,7 @@ if (arguments._.length > 2 || arguments.help === true) {
}
if (arguments.version !== undefined) {
const version = JSON.parse(fs.readFileSync(path.join(__dirname, '../package.json'), 'utf-8')).version
console.log(` https-server v${version}\n`)
console.log(webServer.version())
process.exit()
}
......@@ -59,7 +58,7 @@ if (!fs.existsSync(pathToServe)) {
}
// Start the server.
httpsServer.serve({
webServer.serve({
path: pathToServe,
port,
global
......
......@@ -14,7 +14,14 @@ const redirectHTTPS = require('redirect-https')
const nodecert = require('@ind.ie/nodecert')
class HttpsServer {
class WebServer {
// Returns a nicely-formatted version string based on
// the version set in the package.json file. (Synchronous.)
version () {
const version = JSON.parse(fs.readFileSync(path.join(__dirname, './package.json'), 'utf-8')).version
return `\n 💖 Indie Web Server v${version}\n`
}
// Returns an https server instance – the same as you’d get with
// require('https').createServer() – configured with your locally-trusted nodecert
// certificates by default. If you pass in {global: true} in the options object,
......@@ -39,9 +46,11 @@ class HttpsServer {
// • path: (string) the path to serve (defaults to the current working directory).
// • callback: (function) the callback to call once the server is ready (a default is provided).
// • port: (integer) the port to bind to (between 0 - 49,151; the default is 443).
// • global:
//
// • global: (boolean) if true, automatically provision an use Let’s Encrypt TLS certificates.
serve (options) {
console.log(this.version())
// The options parameter object and all supported properties on the options parameter
// object are optional. Check and populate the defaults.
if (options === undefined) options = {}
......@@ -92,7 +101,7 @@ class HttpsServer {
//
_createTLSServerWithLocallyTrustedCertificate (options, requestListener = undefined) {
console.log(' 🚧 [https-server] Using locally-trusted certificates.')
console.log(' 🚧 [Indie Web Server] Using locally-trusted certificates.')
// Ensure that locally-trusted certificates exist.
nodecert()
......@@ -111,7 +120,7 @@ class HttpsServer {
_createTLSServerWithGloballyTrustedCertificate (options, requestListener = undefined) {
console.log(' 🌍 [https-server] Using globally-trusted certificates.')
console.log(' 🌍 [Indie Web Server] Using globally-trusted certificates.')
// Certificates are automatically obtained for the hostname and the www. subdomain of the hostname
// for the machine that we are running on.
......@@ -140,7 +149,7 @@ class HttpsServer {
const httpsRedirectionMiddleware = redirectHTTPS()
const httpServer = http.createServer(acmeTLS.middleware(httpsRedirectionMiddleware))
httpServer.listen(80, () => {
console.log(' 👉 [https-server] (Globally-trusted TLS) HTTP → HTTPS redirection active.')
console.log(' 👉 [Indie Web Server] HTTP → HTTPS redirection active.')
})
// Add the TLS options from ACME TLS to any existing options that might have been passed in.
......@@ -183,4 +192,4 @@ class HttpsServer {
}
}
module.exports = new HttpsServer()
module.exports = new WebServer()
{
"name": "@ind.ie/https-server",
"version": "5.1.0",
"description": "A secure Small Tech personal web server for seamless development and live use.",
"name": "@ind.ie/web-server",
"version": "6.0.0",
"description": "A secure and seamless Small Tech personal web server.",
"main": "index.js",
"bin": "bin/https-server.js",
"bin": "bin/web-server.js",
"scripts": {
"start": "node index.js",
"test": "tape test/index.js"
},
"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",
......
const test = require('tape')
const httpsServer = require('../index.js')
const webServer = require('../index.js')
const https = require('https')
const indexHTML = "<!DOCTYPE html><html lang='en'><head><title>Test</title><body><h1>Test</h1></body></html>"
......@@ -24,22 +24,22 @@ async function secureGet (url) {
}
test('create https server', t => {
test('createServer method', t => {
t.plan(2)
const server = httpsServer.createServer()
const server = webServer.createServer()
t.ok(server instanceof https.Server, 'is https.Server')
server.listen(443, () => {
t.equal(server.address().port, 443, 'the requested port is set on https.Server')
t.equal(server.address().port, 443, 'the requested port is set on returned https.Server')
t.end()
server.close()
})
})
test('static serve https', t => {
test('serve method', t => {
t.plan(3)
const server = httpsServer.serve({path: 'test/site', callback: async () => {
const server = webServer.serve({path: 'test/site', callback: async () => {
t.ok(server instanceof https.Server, 'is https.Server')
......
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