import * as _ from "lodash" export function expandEndpoint(endpointSpec) { if (typeof endpointSpec === 'string') endpointSpec = { controller: endpointSpec } return endpointSpec } export function expand(spec) { if (!spec.name || typeof spec.name !== 'string') throw new Error(`must provide a name as a string`) if (!/[a-z](-[a-z0-9]+)*/.test(spec)) throw new Error(`${spec.name} is an invalid name`) _.defaults(spec, { port: 8080 }) for (const key of Object.keys(spec.endpoints)) { spec.endpoints[key] = expandEndpoint(spec.endpoints[key]) } return spec }