|
1 | 1 | import {IBeaconNodeOptions, allNamespaces, defaultOptions} from "@lodestar/beacon-node"; |
2 | 2 | import {CliCommandOptions} from "@lodestar/utils"; |
3 | 3 |
|
4 | | -const enabledAll = "*"; |
| 4 | +export const enabledAll = "*"; |
| 5 | +export const enabledAllBashFriendly = "all"; |
| 6 | + |
| 7 | +/** |
| 8 | + * Coerce function to transform bash-friendly 'all' to CORS spec '*' |
| 9 | + */ |
| 10 | +export function coerceCors(cors: string): string { |
| 11 | + return cors === enabledAllBashFriendly ? enabledAll : cors; |
| 12 | +} |
5 | 13 |
|
6 | 14 | export type ApiArgs = { |
7 | 15 | "api.maxGindicesInProof"?: number; |
@@ -51,23 +59,25 @@ export const options: CliCommandOptions<ApiArgs> = { |
51 | 59 |
|
52 | 60 | "rest.namespace": { |
53 | 61 | type: "array", |
54 | | - choices: [...allNamespaces, enabledAll], |
55 | | - description: `Pick namespaces to expose for HTTP API. Set to '${enabledAll}' to enable all namespaces`, |
| 62 | + choices: [...allNamespaces, enabledAll, enabledAllBashFriendly], |
| 63 | + description: `Pick namespaces to expose for HTTP API. Set to '${enabledAllBashFriendly}' (or '${enabledAll}') to enable all namespaces`, |
56 | 64 | defaultDescription: JSON.stringify(defaultOptions.api.rest.api), |
57 | 65 | group: "api", |
58 | 66 | coerce: (namespaces: string[]): string[] => { |
59 | | - // Enable all |
60 | | - if (namespaces.includes(enabledAll)) return allNamespaces; |
| 67 | + if (namespaces.includes(enabledAll) || namespaces.includes(enabledAllBashFriendly)) { |
| 68 | + return allNamespaces; |
| 69 | + } |
61 | 70 | // Parse ["debug,lodestar"] to ["debug", "lodestar"] |
62 | 71 | return namespaces.flatMap((val) => val.split(",")); |
63 | 72 | }, |
64 | 73 | }, |
65 | 74 |
|
66 | 75 | "rest.cors": { |
67 | 76 | type: "string", |
68 | | - description: "Configures the Access-Control-Allow-Origin CORS header for HTTP API", |
| 77 | + description: `Configures the Access-Control-Allow-Origin CORS header for HTTP API. Use '${enabledAllBashFriendly}' to allow all origins`, |
69 | 78 | defaultDescription: defaultOptions.api.rest.cors, |
70 | 79 | group: "api", |
| 80 | + coerce: coerceCors, |
71 | 81 | }, |
72 | 82 |
|
73 | 83 | "rest.address": { |
|
0 commit comments