Variable: buildServiceEntrypoint
constbuildServiceEntrypoint: (entrypoint) =>ServiceEntrypoint
Type a service entrypoint in the style of lakutata 2.x; the function is returned as it is.
Parameters
entrypoint
The function the entrypoint calls when it starts, with the module, the request handler and the destroyer registrar.
Returns
The same function, to give to the service option of buildEntrypoints.
Example
typescript
import {EventEmitter} from 'node:events'
import {Application} from 'lakutata'
import {buildEntrypoints, buildServiceEntrypoint, Controller, ServiceContext} from 'lakutata/com/entrypoint'
import {ServiceAction} from 'lakutata/decorator/ctrl'
declare const bus: EventEmitter
class MathController extends Controller {
@ServiceAction({ctrl: 'math', act: 'add'})
public async add(input: {a: number, b: number}): Promise<number> {
return input.a + input.b
}
}
Application.run(() => ({
id: 'math.app',
name: 'Math',
components: {
entrypoint: buildEntrypoints({
controllers: [MathController],
//Each message of the bus is a request: its data matched against the patterns of the actions
service: buildServiceEntrypoint((module, handler, registerDestroy): void => {
const listener = async (data: Record<string, any>, reply: (result: unknown) => void): Promise<void> => {
reply(await handler(new ServiceContext({data: data})))
}
bus.on('request', listener)
registerDestroy((): void => void bus.off('request', listener))
})
})
},
bootstrap: ['entrypoint']
}))