WEBCORE Configuration file

Hi,

I have a WebCore Project with a differents functionalities. This functionalities was based on data that i retrieve from database using Rest calls to a remote Rest Server usinf httprequest...

The purpose of this project is to be deployed in different servers ans installations... But i want only one version of the project.

In the project, when i want to call a method of a rest server i write the uri like this: https://customers.madd.com/univers/rm/rmserver/......

The variable part of uri is the base url... https://customers.madd.com

This part is different in all the servers...

I would like to have an .ini file (for example) on the server, in the location of the apache html where i edit ans put into this and other parameters...

Then, when i use the html in the client side i see into this file what is the url of the rest server for call methods... or any other parameters that i can nedd...

You know how can i do this ? Any idea for the best practice to do this ?

Thanks !

You should be able to use a TWebHTTPRequest to request the content of this config file and use this content in your code.

Hi Bruno,

Yes i do this with TWebHTTPRequest as you say. For example:

TWebHTTPRquest.URL:='http://192.168.25.199:8082/rm//rmserver/TSserver/CallFunctio…/192.168.25.188/madddoc.df_apiw.ValidaUsuario/CLI010558/madd'

This code retrieve to my data from rest server...

Rest Server is located in http://192.168.25.199:8082...

I put this value (http://192.168.25.199:8082) in a global variable or in a local TWebLocalDataStore in the mainform an i can read this value along the web when i need it, etc...

If this project is installed and run in one server, all is ok...

But i want to use this project for install in any other servers, and the rest server of any installation is in the different url... Then i want to have, for example, one INI file in the /var/www/html folder of the server for indicate the singular url for this server in order that the html use this value for the TWebHTTPRequestURL...

For example, in this project there are one image for the logo of my customer... This image is in the TTMSFNCImage component in the webform. Then, in the form, in the event of OnCreate of he form i do:

 Image.bitmap.loadfromfile('logo.png');

Then in the folder of /var/www/html/ are a logo.png file..

When i install a new web application for other customer, i put their logo in this file, and in the web their logo appear and i not have to modify my source code...

I want to do the same with the URL of rest server...

Do you know how can i do this ?

Thanks

I use a JSON file for my config and use (I'm using XData) and store the config file in the subdirectory of the website config:

Conn := TXDataWebConnection.Create(Nil);
  Try
    Conn.SendRequest(THttpRequest.Create('config/config.json'), @OnSuccess, @OnError);
  Finally
    Conn.Free;
  End;

If I was doing this now I'd use Await(IHttpResponse, SendRequestAsync)

In OnSuccess I retrieve the URLs:

Procedure OnSuccess(Response: IHttpResponse);
  Var
    Obj: TJSObject;
    Config: TAppConfig;
    lResponse: String;
  Begin
    Config := TAppConfig.Create;
    Try
      If Response.StatusCode = 200 Then
      Begin
        lResponse := Response.ContentAsText;
        Obj := TJSObject(TJSJSON.parse(lResponse));

        If JS.toString(Obj['BaseUrl']) <> '' Then
          Config.BaseUrl := JS.toString(Obj['BaseUrl']);
        If JS.toString(Obj['AuthUrl']) <> '' Then
          Config.AuthUrl := JS.toString(Obj['AuthUrl']);

      End;
    Finally
      LoadProc(Config);
      Config.Free;
    End;
  End;
1 Like

Hi Russell,

I do not use XData but i think that i can do the same with TWebHTTPRequest...

I try it...

Thanks for your response !

1 Like

Yes you should be able to do that.

Hi Russell,

Your solution works perfectly for me.

Thanks for your help !

1 Like

This topic was automatically closed 60 minutes after the last reply. New replies are no longer allowed.