ROJavaScriptHttpDispatcher with path = '/'

Hi everyone.I have a demo project with RoJavaScriptHttpDispatcher configured with the path property = ‘/’.

Maybe i am missing something but I need to send the request from the browser just with the URL (http(s)://www.misite.com) without adding folder name (http(s)://www.misite.com/foldername)

Is this the right way to achive this?

thanks in advance.

pls specify your platform (Delphi, .NET, etc)

sorry. The platform i am using is Delphi XE7 with RO8.3.93.1183.

Thanks

Why do you need to use / path? It may conflict with another dispatchers like HTTPApi and OData …

TROJavaScriptHttpDispatcher doesn’t work with / path correctly.
but you can set this path and manually process it via OnRequest event.

by other hand, you can process / path via OnCustomResponseEvent handler or HTTPServer.
see more at Using OnCustomResponseEvent in a ROSDK Server

I need to use it because i have a web application that mix html content and javascript functions that use remote services to send and recive data. I did open a domain and i need that the web application load and respond when i enter de URL for example: http://mysite.com.

The configuration of the javascript dispatcher needs a different value than just “/” so when i assign the “/app/” value to the property “path” i need in the URL to write “http://mysite.com/app”.What i don´t want is to write “/app/”, just the domain.

Which is the right way to achive this?

by the way i have implemented messages dispatchers (bin and json).

thanks.

  • keep /app/ path for ROJavaScriptHttpDispatcher.
  • add OnCustomResponseEvent event like:
procedure TMegaDemoServerMainForm.ROIndyHTTPServer1CustomResponseEvent(
  const aTransport: IROHTTPTransport; const aRequestStream,
  aResponseStream: TStream; const aResponse: IROHTTPResponse;
  var aHandled: Boolean);
begin
  aTransport.PathInfo := '/app'+aTransport.PathInfo; // modify path
  ROJavaScriptHttpDispatcher.Process(aTransport,aTransport as IROHTTPRequest,aResponse,aRequestStream,aResponseStream);
  aHandled := true;
end;

Note: this works for TROIndyHTTPServer only , for other http server, it could be differ.

I will try it and let you know.

Thank you very much

Hello. I did try the code but it didn’t works, the event is never reached.

I did some changes to the file uROHTTPFileDispatcher.pas and now a get what i want but i’m not sure if those changes will affect in other way.

The code i had changed is:

ProcessMethod

if fServeFilesFromFolder then
if(AnsiSameText(’/’+lPatchComponents[1]+’/’, Path)) or (Path=’/’) then begin
if(lPathComponentes.Count = 2) and (Path<>’/’)then begin

end
end
else begin
lFilePath := fFolder;
if(Path <> ‘/’) then d:=2 else d := 1;
for i := d to lPathComponents.Count - 1 do begin

end
if((lPathComponents.Coint > 2) and (lPathComponents[lPathComponents.Count-1] = ‘’)) or
((lPathComponents.Coint = 2) and (lPathComponents[lPathComponents.Count-1] = ‘’) and (Path = ‘/’)) then begin

end;

end;

What do you think about it?

Thanks in advance

Sorry, I forgot to say that you need also set Server.ServeInfoPage to False.
I’ve attached testcase.
try to open http://127.0.0.1:8099/ and http://127.0.0.1:8099/app/, result will be the same.
testcase.zip (29.9 KB)

1 Like

that works perfect.

thank you very much.

until the next time.