pockethost 1.3.1 → 1.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +18 -0
- package/core.ts +0 -1
- package/package.json +4 -4
- package/readme.md +1 -1
- package/src/cli/commands/ServeCommand/index.ts +19 -4
- package/src/cli/index.ts +6 -5
- package/src/common/plugin/action.ts +5 -0
- package/src/common/plugin/filter.ts +5 -0
- package/src/constants.ts +2 -8
- package/src/server.ts +22 -9
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,23 @@
|
|
|
1
1
|
# pockethost
|
|
2
2
|
|
|
3
|
+
## 1.4.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- b7e4323: Added ability for plugins to respond to `pockethost serve`
|
|
8
|
+
|
|
9
|
+
## 1.3.2
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- b0a78d8: Updated plugin authoring guide
|
|
14
|
+
- ac63ea7: Updated plugin documentation
|
|
15
|
+
- Updated dependencies [eb0d011]
|
|
16
|
+
- Updated dependencies [38d2c93]
|
|
17
|
+
- @pockethost/plugin-launcher-spawn@0.2.0
|
|
18
|
+
- @pockethost/plugin-console-logger@0.2.0
|
|
19
|
+
- @pockethost/plugin-auto-admin@0.1.0
|
|
20
|
+
|
|
3
21
|
## 1.3.1
|
|
4
22
|
|
|
5
23
|
### Patch Changes
|
package/core.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pockethost",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.4.0",
|
|
4
4
|
"author": {
|
|
5
5
|
"name": "Ben Allfree",
|
|
6
6
|
"url": "https://github.com/benallfree"
|
|
@@ -39,9 +39,9 @@
|
|
|
39
39
|
"typescript": "^5.4.5",
|
|
40
40
|
"update-notifier": "^7.0.0",
|
|
41
41
|
"url-pattern": "^1.0.3",
|
|
42
|
-
"@pockethost/plugin-console-logger": "^0.
|
|
43
|
-
"@pockethost/plugin-
|
|
44
|
-
"@pockethost/plugin-
|
|
42
|
+
"@pockethost/plugin-console-logger": "^0.2.0",
|
|
43
|
+
"@pockethost/plugin-auto-admin": "^0.1.0",
|
|
44
|
+
"@pockethost/plugin-launcher-spawn": "^0.2.0"
|
|
45
45
|
},
|
|
46
46
|
"devDependencies": {
|
|
47
47
|
"@types/express": "^4.17.21",
|
package/readme.md
CHANGED
|
@@ -63,7 +63,7 @@ Coming soon:
|
|
|
63
63
|
| plugin-waf-enforce-ssl | Enforce SSL at the
|
|
64
64
|
WAF
|
|
65
65
|
|
|
66
|
-
See the [
|
|
66
|
+
See the [Plugin Authoring Guide](https://github.com/pockethost/pockethost/blob/master/packages/pockethost/plugin-guide.md) for details about what hooks and filters are available.
|
|
67
67
|
|
|
68
68
|
## Support
|
|
69
69
|
|
|
@@ -1,20 +1,35 @@
|
|
|
1
1
|
import { Command } from 'commander'
|
|
2
|
-
import {
|
|
3
|
-
|
|
2
|
+
import {
|
|
3
|
+
LoggerService,
|
|
4
|
+
doServeAction,
|
|
5
|
+
doServeSlugsFilter,
|
|
6
|
+
} from '../../../common'
|
|
4
7
|
|
|
5
8
|
type Options = {
|
|
6
9
|
isolate: boolean
|
|
7
10
|
}
|
|
8
11
|
|
|
9
|
-
export const ServeCommand = () => {
|
|
12
|
+
export const ServeCommand = async () => {
|
|
13
|
+
const serveSlugs = await doServeSlugsFilter([])
|
|
14
|
+
|
|
10
15
|
const cmd = new Command(`serve`)
|
|
11
16
|
.description(`Run PocketHost`)
|
|
17
|
+
.option(
|
|
18
|
+
`-o, --only <only>`,
|
|
19
|
+
`Only run the specified services`,
|
|
20
|
+
(s) =>
|
|
21
|
+
s
|
|
22
|
+
.split(/,/)
|
|
23
|
+
.map((s) => s.trim())
|
|
24
|
+
.filter((s) => serveSlugs.includes(s)),
|
|
25
|
+
serveSlugs,
|
|
26
|
+
)
|
|
12
27
|
.action(async (options: Options) => {
|
|
13
28
|
const logger = LoggerService().create(`ServeCommand`)
|
|
14
29
|
const { dbg, error, info, warn } = logger
|
|
15
30
|
info(`Starting`)
|
|
16
31
|
|
|
17
|
-
await
|
|
32
|
+
await doServeAction({ only: serveSlugs })
|
|
18
33
|
})
|
|
19
34
|
return cmd
|
|
20
35
|
}
|
package/src/cli/index.ts
CHANGED
|
@@ -4,15 +4,15 @@ import { uniq } from '@s-libs/micro-dash'
|
|
|
4
4
|
import { program } from 'commander'
|
|
5
5
|
import { readFileSync } from 'fs'
|
|
6
6
|
import updateNotifier from 'update-notifier'
|
|
7
|
+
import { PH_PLUGINS, PH_PROJECT_DIR } from '../../core'
|
|
7
8
|
import {
|
|
8
9
|
DEBUG,
|
|
9
10
|
LogLevelName,
|
|
10
11
|
LoggerService,
|
|
11
|
-
PH_PLUGINS,
|
|
12
|
-
PH_PROJECT_DIR,
|
|
13
12
|
doCliCommandsFilter,
|
|
14
13
|
loadPlugins,
|
|
15
|
-
} from '
|
|
14
|
+
} from '../common'
|
|
15
|
+
import { pockethost } from '../server'
|
|
16
16
|
import { ConfigCommand } from './commands/ConfigCommand'
|
|
17
17
|
import { PluginCommand } from './commands/PluginCommand'
|
|
18
18
|
import { ServeCommand } from './commands/ServeCommand'
|
|
@@ -22,7 +22,8 @@ export const { dbg, info, error } = LoggerService({
|
|
|
22
22
|
})
|
|
23
23
|
|
|
24
24
|
export const main = async () => {
|
|
25
|
-
await loadPlugins(uniq(PH_PLUGINS()))
|
|
25
|
+
await loadPlugins([pockethost, ...uniq(PH_PLUGINS())])
|
|
26
|
+
|
|
26
27
|
const pkg = await JSON.parse(
|
|
27
28
|
readFileSync(PH_PROJECT_DIR(`package.json`), 'utf8').toString(),
|
|
28
29
|
)
|
|
@@ -36,7 +37,7 @@ export const main = async () => {
|
|
|
36
37
|
.version(version)
|
|
37
38
|
|
|
38
39
|
const commands = await doCliCommandsFilter([
|
|
39
|
-
ServeCommand(),
|
|
40
|
+
await ServeCommand(),
|
|
40
41
|
ConfigCommand(),
|
|
41
42
|
PluginCommand(),
|
|
42
43
|
])
|
|
@@ -5,6 +5,7 @@ import { InstanceFields } from '../schema'
|
|
|
5
5
|
|
|
6
6
|
enum CoreActions {
|
|
7
7
|
Init = 'core_init',
|
|
8
|
+
Serve = 'core_serve',
|
|
8
9
|
AppMounted = 'core_on_app_mount',
|
|
9
10
|
AfterServeStart = 'core_after_serve_start',
|
|
10
11
|
|
|
@@ -125,3 +126,7 @@ export const [doAfterInstanceStoppedAction, onAfterInstanceStoppedAction] =
|
|
|
125
126
|
createCustomActionWithContext<{ instance: InstanceFields; url: string }>(
|
|
126
127
|
CoreActions.AfterInstanceStopped,
|
|
127
128
|
)
|
|
129
|
+
|
|
130
|
+
export const [doServeAction, onServeAction] = createCustomActionWithContext<{
|
|
131
|
+
only: string[]
|
|
132
|
+
}>(CoreActions.Serve)
|
|
@@ -5,6 +5,7 @@ import { InstanceFields, InstanceId } from '../schema'
|
|
|
5
5
|
|
|
6
6
|
export enum CoreFilters {
|
|
7
7
|
CliCommands = 'core_cli_commands',
|
|
8
|
+
ServeSlugs = 'core_serve_slugs',
|
|
8
9
|
SpawnConfig = 'core_spawn_config',
|
|
9
10
|
GetInstanceByRequestInfo = 'core_get_instance_by_request_info',
|
|
10
11
|
GetInstanceById = 'core_get_instance_by_id',
|
|
@@ -113,3 +114,7 @@ export const [
|
|
|
113
114
|
instance: InstanceFields
|
|
114
115
|
}
|
|
115
116
|
>(CoreFilters.GetOrProvisionInstanceUrl)
|
|
117
|
+
|
|
118
|
+
export const [doServeSlugsFilter, onServeSlugsFilter] = createCustomFilter<
|
|
119
|
+
string[]
|
|
120
|
+
>(CoreFilters.ServeSlugs)
|
package/src/constants.ts
CHANGED
|
@@ -4,14 +4,8 @@ import envPaths from 'env-paths'
|
|
|
4
4
|
import { dirname, join } from 'path'
|
|
5
5
|
import { cwd } from 'process'
|
|
6
6
|
import { fileURLToPath } from 'url'
|
|
7
|
-
import {
|
|
8
|
-
|
|
9
|
-
mkBoolean,
|
|
10
|
-
mkCsvString,
|
|
11
|
-
mkNumber,
|
|
12
|
-
mkPath,
|
|
13
|
-
mkString,
|
|
14
|
-
} from '../core'
|
|
7
|
+
import { mkBoolean, mkCsvString, mkNumber, mkPath, mkString } from '../core'
|
|
8
|
+
import { InstanceId } from './common'
|
|
15
9
|
import { DEBUG, IS_DEV } from './common/debug'
|
|
16
10
|
import { Settings } from './core/Settings'
|
|
17
11
|
|
package/src/server.ts
CHANGED
|
@@ -2,10 +2,8 @@ import express, { ErrorRequestHandler } from 'express'
|
|
|
2
2
|
import 'express-async-errors'
|
|
3
3
|
import { default as httpProxy } from 'http-proxy'
|
|
4
4
|
import {
|
|
5
|
-
APEX_DOMAIN,
|
|
6
5
|
LoggerService,
|
|
7
|
-
|
|
8
|
-
asyncExitHook,
|
|
6
|
+
PocketHostPlugin,
|
|
9
7
|
doAfterInstanceFoundAction,
|
|
10
8
|
doAfterServerStartAction,
|
|
11
9
|
doAppMountedAction,
|
|
@@ -15,16 +13,16 @@ import {
|
|
|
15
13
|
doRequestErrorAction,
|
|
16
14
|
doRequestErrorMessageFilter,
|
|
17
15
|
onInstanceLogAction,
|
|
18
|
-
|
|
16
|
+
onServeAction,
|
|
17
|
+
onServeSlugsFilter,
|
|
18
|
+
} from '../common'
|
|
19
|
+
import { APEX_DOMAIN, PORT, asyncExitHook } from '../core'
|
|
20
|
+
import { dbg } from './cli'
|
|
19
21
|
|
|
20
|
-
|
|
22
|
+
const serve = async () => {
|
|
21
23
|
const _proxyLogger = LoggerService().create('ProxyService')
|
|
22
24
|
const { dbg, error, info, trace, warn } = _proxyLogger
|
|
23
25
|
|
|
24
|
-
onInstanceLogAction(async ({ instance, type, data }) => {
|
|
25
|
-
dbg(data.toString())
|
|
26
|
-
})
|
|
27
|
-
|
|
28
26
|
// registerFilter(
|
|
29
27
|
// CoreFilters.Waf_VHosts,
|
|
30
28
|
// async (routes: { [_: string]: string }) => {
|
|
@@ -113,3 +111,18 @@ export const serve = async () => {
|
|
|
113
111
|
info(`Shutting down pockethost`)
|
|
114
112
|
})
|
|
115
113
|
}
|
|
114
|
+
|
|
115
|
+
export const pockethost: PocketHostPlugin = async ({}) => {
|
|
116
|
+
onInstanceLogAction(async ({ instance, type, data }) => {
|
|
117
|
+
dbg(data.toString())
|
|
118
|
+
})
|
|
119
|
+
|
|
120
|
+
onServeAction(async ({ only }) => {
|
|
121
|
+
if (!only.includes(`pockethost`)) return
|
|
122
|
+
serve()
|
|
123
|
+
})
|
|
124
|
+
|
|
125
|
+
onServeSlugsFilter(async (slugs) => {
|
|
126
|
+
return [...slugs, `pockethost`]
|
|
127
|
+
})
|
|
128
|
+
}
|