/!\ Project is not stable /!\
Olive Manager is node server for manage the Olive micro services. He is manage the HTTP server and relays the request to micro services !
- Clone the repository !
- Use
npm ifor install dependency - Use
npm run watchfor build and rebuild in case of a change in a file - And use
nodemonon other terminal for launch the manager
The files test.js and testAuth.js is micro service for test the manager.
- Use
nodemon testAuth.jsfor launch a micro service AuthTest ! Who's going to connect on manager as an auth service ! - Use
nodemon test.jsfor launch a micro service Test ! Who's going to connect on manager. - For call the micro service Test you can call
GET http://localhost:9999/test - If an 401 is returned check if AuthTest is loaded and if is initialized
- And now you can dev.
- Use
npm i -g olive-managerfor install Olive Manager - Use
olive startfor launch the manager - You can change the default port whit option
--port 80or-p 80 - You can change the default microservice port whit option
--msport 1234or-msp 1234
PS: Manager use pm2 for launch server
The micro service is connected to the manager with a TCP socket and for all request the format is a JSON.
For any request the interface is :
{
name: string, // Type of request. Exemple : "response" or "config"
uid: number, // The unique id
data: any, // The content of request
}
The manage support many type !
- The type
configallows to configure the micro service in Manager. - The type
responsewhen the micro service respond has an request of the manager - The type
authResponsewhen the Auth micro service respond has an request of the manager
For any types the params data as a special interface :
data: {
"name": string, // The name of micro service
"requireAuth": boolean // If true, the micro service require authentification
"isAuth": boolean // The service is the AuthService or not
}
The params name will be used for create route and for differentiated the micro services. If name is user so the route for call the user micro service is {{HOST}}/user !
The params requireAuth define if the micro service require a auth for they routes (All routes of micro service). If is true, at the moment on the manager get an request, he send in first part the request to the AuthService and once the AuthService as responde the manager resend the request to the micro service ! Is the authService return an other status of 200, the manager return the error status code !
The params isAuth define if the micro service should be considered as a AuthService.
data: {
headers: {
status: number // HTTP Status
}
body: any // All neceseray information for service
}
The params status is the http code returned by the service if the is 200 the request continue that propagation, but if is not 200 the manager send an http response with the status code.
The params data is send unaltered form the client http
data: {
headers: {
status: number // HTTP Status
}
body: any // All neceseray information for authService
}
The params status is the http code returned by the auth service if the is 200 the request continue that propagation, but if is not 200 the manager send an http response with the status code.
The params data is an object where all params is send to the next service with auth data. For exemple he contain the user data.
The manager send various type of the request.
For any request the manager send allways from the same interface :
{
name: string, // Name for the request type
uid: number, // the unique id, allways build by the manager
data: any, // All data send with HTTP request, query and/or body
auth: any, // the data send by the auth service
requestParams: object // Is the information from the http request
}
The type request send to micro service when the manager get an http request
The type requestAuth is send to auth micro service for authenticate the current http request
On start manager, the different micro services connect to the manager and micro service send a request config !
On manager recieve a http request, the manager check if micro service where the request must be send is load and init.
If micro service is ok, the manager check if the micro service require an auth, if is true, he (the manager) send a request to auth micro service ('requestAuth').
If the auth service return an http code 200, this manager send the request to micro service, and after the answer of the micro service, the manager re-send the answer to http client .
If the auth service return an other http code the manager send the code to http client.