Add microservice to loraserver

I have loraserver deployed on server and everything works fine.
We added microservice that listen for mqtt RX packets and stores them to postgres database in separate table “payload”.
Now we need to create appllication web server that retrieves that stored data and provides UI web interface for end user. But we want to reuse existinglora-app-server source code as much as possible. At least we want to reuse lora-app-server's autorization mechanism, that decides what end nodes and company information can access current user.
As I see, login page sends request to /api/internal/login endpoint. We found mention of this endpoint in /api/swagger/internal.swagger.json file. So seems we can start from taking existing swagger file and modifying it to use only required endpoints?
Can someone point me how to extract autorization mechanism from source code in the easiest way?

Trying to debug user login procedure as required for service we are developing currently. So there is following flow from /api/internal/login URL request on frontend to database query via backend request handling:
api/internal.pb.go _InternalService_Login_Handler() calls
internal/api/external/user.go Login() which calls
internal/storage/user.go LoginUser() which calls
internal/storage/db.go QueryRowx() request to database.
Does it mean that adding new functionality starts from modification of proto files and generating pb.go source files from them?
Or swagger.json is starting point?

Hi, so if you want to make some modifications in the REST API, then first you have to modify the lora-app-server > api > .proto files and then .pb.go and .swagger.json files will be automatically generated using make api command. You cannot edit the compiler generated files (i.e. .pb.go and .swagger.json), in order to edit them you have to only edit proto definitions.

After that you have to add, the changes made in the respective.go files and .js files.

Same process follows with loraserver too.

1 Like

The issue was that I registered new grpc server:

	api.RegisterMessageServiceServer(grpcServer, NewMessageAPI(validator))

but forgot to register URL handler:

	if err := pb.RegisterMessageServiceHandlerFromEndpoint(ctx, mux, apiEndpoint, grpcDialOpts); err != nil {
		return nil, errors.Wrap(err, "register message handler error")

Now it works. Thank you.

1 Like