XData and "Exclusive mode"

Hi Wagner,

is it possible to put XData in an exclusive mode?
For service functions (e.g. updates, execution of database scripts) I would like to switch my XData REST server to an exclusive mode so that nobody else has access and then execute various scripts via my database module (direct Firedac connection).
I myself also access the server via Http/REST.

Are there any functions? Something ready?
Alternatively, I would have to do this via my own synchonize function in the MainThread. (I already use this for communication with special USB devices). Or I do something using authorization.

Hi Thomas,

Sorry but I didn't understand what you mean by exclusive mode. You mean to completely stop the server? Can't you simply do just that, stop the server?

Or you can add a middleware which rejects all requests if a flag is set.

A middleware seems to be the right approach.
I can't stop the server because I still have to work on it myself.

I would like to block all connections for the duration of the supports work. But I myself (the admin/support user) must be allowed to work (via the network). I have a property "Support" in the claim of the JWT. I can use that.

Do you have an example for to do this?
I use a "TSparkleGenericMiddleware" for a 2nd logging function. But that is only one line in the XDataServer - "XDataServerGenericMiddlewareCreate"-Event. I don't have any more experience on the subject (middleware).

Just use a generic middleware and use its OnRequest event. There you have the context which you can use to read the request and send a response. This is a rough example (untested):

procedure TForm1.XDataServer1GenericRequest(Sender: TObject; Context: THttpServerContext; Next: THttpServerProc);
begin
  if ServerIsExclusive and not IsSupportUser(Context.Request.User) then
  begin
    Context.Response.StatusCode := 503; // server not available
    Context.Response.Close;
  end
  else
    Next(Context);
end;

That looks good. I will test it soon. I'm currently busy with customer support.
Thank you

1 Like