backoffice microservice example powered by tom-microservice
You need to install the project dependencies with npm install
Then you are ready to run tom ๐ถ
Your configuration project live at tom.config.js.
Under the hood we are using config
for differenciate between development and production credentials.
Notes that every time an action was called, it will be emit an event. You can use this event for connect the service with your specific code:
tom.on('payment:create', data => {
console.log('payment:create', data)
})
tom.on('payment:update', data => {
console.log('payment:update', data)
})
tom.on('notification', data => {
console.log('notification', data)
return {foo: 'bar'}
})
tom.on('notification:email', data => {
console.log('notification:email', data)
return {hello: 'bar'}
})
tom.on('*', (data) => {
console.log('global notification', data)
return {kiko: 'bar'}
})
The payload that you return in each event will be print by the command execution, for example:
$ tom --command=notification.email --templateId=summary [email protected] --username=Leo
will be print the following log:
notification:email [email protected] [email protected] subject='[hyperping.io] Weekly Report' [email protected] preview=https://ethereal.email/message/W1ZFkRVUhwyoi4LGW1bVFavoFgz2lN8AAAAAev9pdp8u5UhfRuVObjtoDPU kiko=bar foo=bar hello=bar
Just run npx tom
passing the flags for execute a certain command, for example:
npx tom --command=notification.email --templateId=summary [email protected] --username=Leo
You can use tom --help
or see scripts to see it in action.
Running npm run dev
start a development HTTP server in your machine.
Execute for started a HTTP server in your machine. The server has hot reloading.
You can deploy tom ๐ถ to production after attach the following information at config/production.yaml
- Stripe API Key: It is uses by
payment
commands - Email transporter credentials: It is uses by
notification:email
commands.
After that, just run your service with npm start
๐
Check Environment Variables section in the doc in case you want to associate a port or and API key for protect your microservice for external requests.