Jump to content

KostasR

Members
  • Content Count

    4
  • Joined

  • Last visited

Community Reputation

1 Neutral

Recent Profile Visitors

The recent visitors block is disabled and is not being shown to other users.

  1. KostasR

    [Source code for sale] Automated Whatsapp server

    Hi, please send me too the demo version and the cost of source code: I'm really interested 🙂
  2. KostasR

    MARSWebServer Compile error

    Hi, Do you mean the MARS\Demo\HelloWorld project? If so, I just compiled it on Delphi 10.4.1. It runs without any problems. If you mean the example MARS\Demos\MARSWebServer, I always use the template from MARS\Demos\MARSTemplate for new projects. Here the resource is registered without the anonymous method. The resource is created implicitly. initialization TMARSResourceRegistry.Instance.RegisterResource<THelloWorldResource>; // TMARSResourceRegistry.Instance.RegisterResource<THelloWorldResource>( // function: TObject // begin // Result := THelloWorldResource.Create; // end // ); There is another difference with Server.Forms.Main.pas FormCreate uses Web.HttpApp , MARS.Core.URL , MARS.Core.MessageBodyWriter, MARS.Core.MessageBodyWriters , MARS.Core.MessageBodyReader, MARS.Core.MessageBodyReaders , MARS.Utils.Parameters.IniFile, MARS.Core.RequestAndResponse.Interfaces ; --- procedure TMainForm.FormCreate(Sender: TObject); begin // MARS-Curiosity Engine FEngine := TMARSEngine.Create; try FEngine.Parameters.LoadFromIniFile; FEngine.AddApplication('DefaultApp', '/default', ['Server.*']); PortNumberEdit.Text := FEngine.Port.ToString; FEngine.BeforeHandleRequest := function (const AEngine: TMARSEngine; const AURL: TMARSURL; const ARequest: IMARSRequest; const AResponse: IMARSResponse; var Handled: Boolean ): Boolean begin Result := True; // skip favicon requests (browser) if SameText(AURL.Document, 'favicon.ico') then begin Result := False; Handled := True; end; // Handle CORS and PreFlight if SameText(ARequest.Method, 'OPTIONS') then begin Handled := True; Result := False; end; end; StartServerAction.Execute; except FreeAndNil(FEngine); raise; end; end; With these two changes I was able to compile and run the MARSWebServer project. http://localhost:8080/rest/default/helloworld In the resource, the path is set to c:\temp. Thus index.html is searched here. Regards, Kostas
  3. Hello All, I would like to log errors. The TMARSActivation.RegisterInvokeError method in Server.Ignition seems to be suitable for this. It is called in the event of an error. But "AActivation.Method" is not assigned, so nothing is logged. Does anyone have any idea how AActivation.Method can be assigned? TMARSActivation.RegisterInvokeError( procedure (const AActivation: IMARSActivation; const AException: Exception; var AHandled: Boolean) var LErrorObj: TJSONObject; begin if Assigned(AActivation.Method) then ^^^^^^^^^^^^^^^^^^ begin LErrorObj := TJSONObject.Create; try LErrorObj.WriteStringValue('error', AException.Message); LErrorObj.WriteStringValue('resource', AActivation.Resource.Name); LErrorObj.WriteStringValue('method', AActivation.Method.Name); LErrorObj.AddPair('url', AActivation.URL.ToJSONObject); AActivation.Response.ContentType := 'application/json'; AActivation.Response.Content := LErrorObj.ToJSON; FThreadFileLog.Log(#13#10 + LErrorObj.ToString); AHandled := True; finally LErrorObj.Free; end; end; end ); Regards, Kostas
  4. Hello All, I am currently trying to link MARS with an IO handler in order to be able to use HTTPS. Inspired by this post, stackoverflow indy-ssl-delphi-server This is what my code looks like. HTTPS is ignored. HTTP requests go through. Does anyone have MARS running with HTTPS? procedure TWEBService.ServiceCreate(Sender: TObject); var LScheduler: TIdSchedulerOfThreadPool; begin Name := TServerEngine.Default.Parameters.ByNameText('ServiceName', Name).AsString; DisplayName := TServerEngine.Default.Parameters.ByNameText('ServiceDisplayName', DisplayName).AsString; if WebRequestHandler <> nil then WebRequestHandler.WebModuleClass := WebModuleClass; FServer := TIdHTTPWebBrokerBridge.Create(nil); FIOHandler.SSLOptions.CertFile := 'certificate.crt'; FIOHandler.SSLOptions.KeyFile := 'private.key'; FIOHandler.SSLOptions.RootCertFile := 'SSLroot.crt'; FIOHandler.SSLOptions.Method := sslvSSLv23; FIOHandler.OnVerifyPeer := IOHandlerVerifyPeer; FServer.IOHandler := FIOHandler; FServer.OnQuerySSLPort := OnQuerySSLPort; try FServer.DefaultPort := TServerEngine.Default.Port; LScheduler := TIdSchedulerOfThreadPool.Create(FServer); try LScheduler.PoolSize := TServerEngine.Default.ThreadPoolSize; FServer.Scheduler := LScheduler; FServer.MaxConnections := LScheduler.PoolSize; FServer.OnParseAuthentication := ParseAuthenticationHandler; except FServer.Scheduler.Free; FServer.Scheduler := nil; raise; end; except FIOHandler.Free; FServer.Free; raise; end; end; Regards, Kostas
×