Verified Commit 1670375d authored by Aral Balkan's avatar Aral Balkan
Browse files

Pass path to serve properly to daemon; flags without = are boolean

parent 488ff8ec
......@@ -12,12 +12,16 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
### Done
## [6.5.0] - 2019-03-31
## [7.0.0] - 2019-03-31
## Added
- --live flag to run as daemon and handle crashes/restarts via integrated pm2 process manager.
## Changed
- (Breaking) Options that are not boolean flags now require an equals sign. This means that boolean flags like --live and --global can now be used before or after the path to be served whereas previously the path would not be registered if a boolean flag was used before it.
## [6.4.0] - 2019-03-31
## Added
......
......@@ -17,6 +17,6 @@ const pathToServe = args[0]
// Run the web server.
const webServer = require('../index.js')
webServer.serve({
pathToServe,
path: pathToServe,
global: true
})
......@@ -7,7 +7,7 @@ const webServer = require('../index.js')
const pm2 = require('pm2')
const childProcess = require('child_process')
const arguments = require('minimist')(process.argv.slice(2))
const arguments = require('minimist')(process.argv.slice(2), {boolean: true})
if (arguments._.length > 2 || arguments.help === true) {
......@@ -39,7 +39,7 @@ if (arguments.version !== undefined) {
// If no path is passed, serve the current folder.
// If there is a path, serve that.
let pathToServe = '.'
if (arguments._.length === 1) {
if (arguments._.length > 0) {
pathToServe = arguments._[0]
}
......@@ -73,7 +73,7 @@ if (arguments.live !== undefined) {
pm2.start({
script: path.join(__dirname, 'daemon.js'),
args: pathToServe,
name: 'indie-web-server',
name: 'web-server',
output: '~/.web-server/logs/output.log',
error: '~/.web-server/logs/error.log',
pid: '~/.web-server/pids/server.pid',
......@@ -94,8 +94,13 @@ if (arguments.live !== undefined) {
stdio: 'pipe'
}
// TODO: Check this for failure.
const output = childProcess.execSync(`sudo ${path.join(__dirname, '../node_modules/pm2/bin/pm2')} startup`, options)
try {
const output = childProcess.execSync(`sudo ${path.join(__dirname, '../node_modules/pm2/bin/pm2')} startup`, options)
} catch (error) {
console.log(` 👿 Failed to add server for auto-launch at startup.\n`)
pm2.disconnect()
process.exit(1)
}
console.log(` 😈 Installed for auto-launch at startup.\n`)
......
{
"name": "@ind.ie/web-server",
"version": "6.5.0",
"version": "7.0.0",
"description": "A secure and seamless Small Tech personal web server.",
"main": "index.js",
"bin": "bin/web-server.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