Using microservices, we will solve the following tasks:
- Users can have two roles: admin and user
- They should be able to choose role upon registration
- Tests for login routes and services
From the feature we can infer the messages we will need in our microservices system and we can also assign it a microservice:
Feature | Message |
---|---|
register | role:user,cmd:register |
login | role:user,cmd:login |
For simplifying the design we will choose to have one microservice handling both create and get user messages.
Thankfully, SenecaJS already has user, auth and admin plugins.
The seneca-auth
plugin is not anymore usable with the new seneca-web
versions which now has its own auth system in place.
In order to have a secure web site, we'd like to run our microservices in a protected environment. Our microservices should not be called from the internet. In AWS we can create private clusters with k8s and kops, whose instances will not be accessible from outside the cloud. To send messages into our microservices world we'll have an interface API as a bridge from internet HTTP requests and our private instances. See below an illustration of that design.
The user's role will be stored in the name
field of the user
entity provided by seneca user's plugin.
The seneca user's plugin is already tested. It does not make sense to do further test for that module. However, a sample test is still to be found in ./services-test/user-login/test.js
.
The routes are supposed to call the microservices API gate to enter into our microservices world.
We want to check that the microservice API is called the right way.
- It should be a tree-style comment system
- No limitation to the depth of the comments
- Comments need approval from admins
- Tests for login routes and services
Here as in the section above we will define our messages:
Feature | Message |
---|---|
list comments | role:comment,cmd:list |
post comment | role:comment,cmd:save |
reply to a comment | role:comment,cmd:reply |
approve comment | role:comment,cmd:approve |
The messages are quite simple and bound to our business valued features.
They will be implemented in the comment
microservice.
Open the shell and place yourself in the project's directory first.
Command name | Command |
---|---|
Start project | npm start |
Monitor services | npm run monitor |
Run tests | npm test |
Run Front End | npm run start-ng |
App | Port |
---|---|
front API | 4222 |
gate Service | 4333 |
Look for TODO
notes within the code with a simple git grep
and you'll find some unresolved dilemmas.
services/comment/plugin.js: //TODO
services/comment/plugin.js- // the plugin 'seneca-store-query' enables to
services/comment/plugin.js- // do 'or' queries with mysql and postgres...