pockethost 1.3.2 → 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 +6 -0
- package/package.json +3 -3
- package/readme.md +1 -1
- package/src/cli/commands/ServeCommand/index.ts +19 -4
- package/src/cli/index.ts +4 -2
- package/src/common/plugin/action.ts +5 -0
- package/src/common/plugin/filter.ts +5 -0
- package/src/server.ts +20 -5
package/CHANGELOG.md
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-
|
|
42
|
+
"@pockethost/plugin-console-logger": "^0.2.0",
|
|
43
43
|
"@pockethost/plugin-auto-admin": "^0.1.0",
|
|
44
|
-
"@pockethost/plugin-
|
|
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
|
@@ -12,6 +12,7 @@ import {
|
|
|
12
12
|
doCliCommandsFilter,
|
|
13
13
|
loadPlugins,
|
|
14
14
|
} from '../common'
|
|
15
|
+
import { pockethost } from '../server'
|
|
15
16
|
import { ConfigCommand } from './commands/ConfigCommand'
|
|
16
17
|
import { PluginCommand } from './commands/PluginCommand'
|
|
17
18
|
import { ServeCommand } from './commands/ServeCommand'
|
|
@@ -21,7 +22,8 @@ export const { dbg, info, error } = LoggerService({
|
|
|
21
22
|
})
|
|
22
23
|
|
|
23
24
|
export const main = async () => {
|
|
24
|
-
await loadPlugins(uniq(PH_PLUGINS()))
|
|
25
|
+
await loadPlugins([pockethost, ...uniq(PH_PLUGINS())])
|
|
26
|
+
|
|
25
27
|
const pkg = await JSON.parse(
|
|
26
28
|
readFileSync(PH_PROJECT_DIR(`package.json`), 'utf8').toString(),
|
|
27
29
|
)
|
|
@@ -35,7 +37,7 @@ export const main = async () => {
|
|
|
35
37
|
.version(version)
|
|
36
38
|
|
|
37
39
|
const commands = await doCliCommandsFilter([
|
|
38
|
-
ServeCommand(),
|
|
40
|
+
await ServeCommand(),
|
|
39
41
|
ConfigCommand(),
|
|
40
42
|
PluginCommand(),
|
|
41
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/server.ts
CHANGED
|
@@ -3,6 +3,7 @@ import 'express-async-errors'
|
|
|
3
3
|
import { default as httpProxy } from 'http-proxy'
|
|
4
4
|
import {
|
|
5
5
|
LoggerService,
|
|
6
|
+
PocketHostPlugin,
|
|
6
7
|
doAfterInstanceFoundAction,
|
|
7
8
|
doAfterServerStartAction,
|
|
8
9
|
doAppMountedAction,
|
|
@@ -12,17 +13,16 @@ import {
|
|
|
12
13
|
doRequestErrorAction,
|
|
13
14
|
doRequestErrorMessageFilter,
|
|
14
15
|
onInstanceLogAction,
|
|
16
|
+
onServeAction,
|
|
17
|
+
onServeSlugsFilter,
|
|
15
18
|
} from '../common'
|
|
16
19
|
import { APEX_DOMAIN, PORT, asyncExitHook } from '../core'
|
|
20
|
+
import { dbg } from './cli'
|
|
17
21
|
|
|
18
|
-
|
|
22
|
+
const serve = async () => {
|
|
19
23
|
const _proxyLogger = LoggerService().create('ProxyService')
|
|
20
24
|
const { dbg, error, info, trace, warn } = _proxyLogger
|
|
21
25
|
|
|
22
|
-
onInstanceLogAction(async ({ instance, type, data }) => {
|
|
23
|
-
dbg(data.toString())
|
|
24
|
-
})
|
|
25
|
-
|
|
26
26
|
// registerFilter(
|
|
27
27
|
// CoreFilters.Waf_VHosts,
|
|
28
28
|
// async (routes: { [_: string]: string }) => {
|
|
@@ -111,3 +111,18 @@ export const serve = async () => {
|
|
|
111
111
|
info(`Shutting down pockethost`)
|
|
112
112
|
})
|
|
113
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
|
+
}
|