Commit aee7b268 authored by Aral Balkan's avatar Aral Balkan

Add --aliases option

parent 18e70830
......@@ -4,7 +4,15 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## [Unreleased]
## Unreleased
## [12.1.0] - 2019-07-07
### Added
- `--aliases` option to specify additional domains to obtain TLS certificates for and respond to.
## [12.0.0] - 2019-07-01
### Added
......
......@@ -282,6 +282,10 @@ If `command` is omitted, behaviour defaults to `serve`.
### Options:
#### For both the `serve` and `enable` commands:
- `--aliases`: Comma-separated list of additional domains to obtain TLS certificates for and respond to.
#### For the `serve` command:
- `--sync-to`: The host to sync to.
......@@ -333,6 +337,7 @@ When you `serve` a site at `@hostname` or use the `enable` command, globally-tru
| Goal | Command |
| ----------------------------------------- | ------------------------------------------------------------- |
| Serve current folder | site @hostname |
| Serve current folder also at aliases | site @hostname --aliases=other.site,www.other.site |
| Serve folder demo* | site demo @hostname |
| | site serve demo @hostname |
| Proxy localhost:1313 to https://hostname | site serve :1313 @hostname |
......
......@@ -67,6 +67,11 @@ function enable (args) {
const absolutePathToServe = path.resolve(pathToServe)
// If there are aliase, we will add them to the configuration so they can
// be passed to the serve command when Site.js is started.
const _aliases = args.named['aliases']
const aliases = _aliases === undefined ? '' : `--aliases=${_aliases}`
// Expectation: At this point, regardless of whether we are running as a regular
// Node script or as a standalone executable created with Nexe, all paths should
// be set correctly.
......@@ -102,7 +107,7 @@ function enable (args) {
RestartSec=1
Restart=always
ExecStart=${executable} ${absolutePathToServe} @hostname
ExecStart=${executable} ${absolutePathToServe} @hostname ${aliases}
[Install]
WantedBy=multi-user.target
......
......@@ -36,6 +36,8 @@ function help () {
const commandLogs = command('logs')
const commandStatus = command('status')
const optionAliases = option('aliases')
const optionSyncFrom = option('sync-from')
const optionSyncTo = option('sync-to')
......@@ -85,6 +87,10 @@ function help () {
${heading('Options:')}
For both ${commandServe} and ${commandEnable} commands:
${optionAliases}\t\t\tSpecify additional domains to obtain TLS certs for and respond to.
For ${commandServe} command:
${optionSyncTo}\t\t\tThe host to sync to.
......@@ -133,6 +139,8 @@ function help () {
• Serve current folder\t\t\t${prompt} ${appName} ${argument('@hostname')}
• Serve current folder also at aliases\t${prompt} ${appName} ${argument('@hostname')} ${optionAliases}=${argument('other.site,www.other.site')}
• Serve folder ${argument('demo')}\t\t\t\t${prompt} ${appName} ${argument('demo')} ${argument('@hostname')}
(shorthand and full)\t\t\t${prompt} ${appName} ${commandServe} ${argument('demo')} ${argument('@hostname')}
......
......@@ -18,6 +18,7 @@ const ensure = require('../lib/ensure')
const tcpPortUsed = require('tcp-port-used')
const clr = require('../../lib/clr')
const ALIASES = 'aliases'
const SYNC_TO = 'sync-to'
const SYNC_FROM = 'sync-from'
const EXIT_ON_SYNC = 'exit-on-sync'
......@@ -93,7 +94,15 @@ function serve (args) {
port = port === null ? 443 : port
path = path === null ? '.' : path
//
// Parse named arguments.
//
// Aliases.
const _aliases = args.named[ALIASES]
const aliases = _aliases === undefined ? [] : _aliases.split(',')
// Sync options.
let syncOptions = null
if (args.named[SYNC_TO] !== undefined) {
......@@ -121,7 +130,8 @@ function serve (args) {
path,
port,
global,
proxyPort
proxyPort,
aliases
}
// Start serving the site.
......
......@@ -66,6 +66,8 @@ class Site {
// • port: (integer) the port to bind to (between 0 - 49,151; the default is 443).
// • global: (boolean) if true, automatically provision an use Let’s Encrypt TLS certificates.
// • proxyPort: (number) if provided, a proxy server will be created for the port (and path will be ignored)
// • aliases: (string) comma-separated list of domains that we should get TLS certs
// for and serve.
//
// Note: if you want to run the site on a port < 1024 on Linux, ensure your process has the
// ===== necessary privileges to bind to such ports. E.g., use require('lib/ensure').weCanBindToPort(port, callback)
......@@ -86,6 +88,7 @@ class Site {
this.pathToServe = typeof options.path === 'string' ? options.path : '.'
this.port = typeof options.port === 'number' ? options.port : 443
this.global = typeof options.global === 'boolean' ? options.global : false
this.aliases = Array.isArray(options.aliases) ? options.aliases : []
// Has a proxy server been requested? If so, we flag it and save the port
// we were asked to proxy. In this case, pathToServe is ignored/unused.
......@@ -513,6 +516,8 @@ class Site {
_createTLSServerWithGloballyTrustedCertificate (options, requestListener = undefined) {
console.log(' 🌍 [Site.js] Using globally-trusted certificates.')
console.log('options', options)
// Certificates are automatically obtained for the hostname and the www. subdomain of the hostname
// for the machine that we are running on.
const hostname = os.hostname()
......@@ -548,6 +553,15 @@ class Site {
communityMember: false,
})
// If additional aliases have been specified, add those to the approved domains list.
acmeTLS.approvedDomains = acmeTLS.approvedDomains.concat(this.aliases)
if (this.aliases !== []) {
const listOfAliases = this.aliases.reduce((prev, current) => {
return `${prev}${current}, `
}, '').slice(0, -2)
console.log(` 👉 [Site.js] Also responding for aliases ${listOfAliases}.`)
}
// Create an HTTP server to handle redirects for the Let’s Encrypt ACME HTTP-01 challenge method that we use.
const httpsRedirectionMiddleware = redirectHTTPS()
......
{
"name": "@small-tech/site.js",
"version": "12.0.0",
"version": "12.1.0",
"description": "Develop, test, and deploy your secure static or dynamic personal web site with zero configuration.",
"main": "index.js",
"bin": "bin/site.js",
......
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