Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Hypha
Tools
Indie Web Server
Commits
d7280cf7
Verified
Commit
d7280cf7
authored
Mar 31, 2019
by
Aral Balkan
Browse files
Add --monitor proxy for pm2 monit
parent
7b2760e1
Changes
1
Hide whitespace changes
Inline
Side-by-side
bin/web-server.js
View file @
d7280cf7
...
...
@@ -9,35 +9,58 @@ const pm2 = require('pm2')
const
childProcess
=
require
(
'
child_process
'
)
const
arguments
=
require
(
'
minimist
'
)(
process
.
argv
.
slice
(
2
),
{
boolean
:
true
})
const
pm2Path
=
path
.
join
(
__dirname
,
'
../node_modules/pm2/bin/pm2
'
)
if
(
arguments
.
_
.
length
>
2
||
arguments
.
help
===
true
)
{
const
usageFolderToServe
=
clr
(
'
folder-to-serve
'
,
'
green
'
)
const
usagePortOption
=
`
${
clr
(
'
--port
'
,
'
yellow
'
)}
=
${
clr
(
'
N
'
,
'
cyan
'
)}
`
const
usageStagingOption
=
`
${
clr
(
'
--staging
'
,
'
yellow
'
)}
`
const
usageLiveOption
=
`
${
clr
(
'
--live
'
,
'
yellow
'
)}
`
const
usageMonitorOption
=
`
${
clr
(
'
--monitor
'
,
'
yellow
'
)}
`
const
usageVersionOption
=
`
${
clr
(
'
--version
'
,
'
yellow
'
)}
`
const
usage
=
`
${
webServer
.
version
()}
${
clr
(
'
Usage:
'
,
'
underline
'
)}
${
clr
(
'
web-server
'
,
'
bold
'
)}
[
${
usageFolderToServe
}
] [
${
usagePortOption
}
] [
${
usageStagingOption
}
] [
${
usageVersionOption
}
]
${
clr
(
'
web-server
'
,
'
bold
'
)}
[
${
usageFolderToServe
}
] [
${
usagePortOption
}
] [
${
usageStagingOption
}
]
[
${
usageLiveOption
}
] [
${
usageMonitorOption
}
]
[
${
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).
•
${
usageStagingOption
}
\tRun as regular process with globally-trusted certificates.
•
${
usageLiveOption
}
\tRun as launch-time daemon with globally-trusted certificates.
•
${
usageVersionOption
}
\t\t\tDisplay the version.
•
${
usageFolderToServe
}
\tPath to the folder to serve (defaults to current folder).
•
${
usagePortOption
}
\t\tThe port to start the server on (defaults to 443).
•
${
usageStagingOption
}
\t\tRun as regular process with globally-trusted certificates.
•
${
usageLiveOption
}
\t\tRun as launch-time daemon with globally-trusted certificates.
•
${
usageMonitorOption
}
\t\tMonitor an already-running live server.
•
${
usageVersionOption
}
\t\tDisplay the version.
`
.
replace
(
/
\n
$/
,
''
).
replace
(
/^
\n
/
,
''
)
console
.
log
(
usage
)
process
.
exit
()
}
// Version.
if
(
arguments
.
version
!==
undefined
)
{
console
.
log
(
webServer
.
version
())
process
.
exit
()
}
// Monitor.
if
(
arguments
.
monitor
!==
undefined
)
{
// Launch pm2 monit.
const
options
=
{
env
:
process
.
env
,
stdio
:
'
inherit
'
}
try
{
childProcess
.
execSync
(
`sudo
${
pm2Path
}
monit`
,
options
)
}
catch
(
error
)
{
console
.
log
(
` 👿 Failed to launch the process monitor.\n`
)
process
.
exit
(
1
)
}
process
.
exit
(
0
)
}
// If no path is passed, serve the current folder.
// If there is a path, serve that.
let
pathToServe
=
'
.
'
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment