B4J Question [ Jserver ] is there any way to know which pages are being loaded inside the WWW folder?

Waldemar Lima

Well-Known Member
Licensed User
Longtime User
Hello everyone, I would like to know if the Jserver allows to know if any page inside the WWW was loaded without having to create a JServlet Handle .
 

Waldemar Lima

Well-Known Member
Licensed User
Longtime User
Yes, with a filter handler.
B4X:
Public Sub Filter(req As ServletRequest, resp As ServletResponse) As Boolean
    Log(req.RequestURI)
    Return True
End Sub

B4X:
srvr.AddFilter("/*", "MonitorFilter", False)
can't write on request ?

i'm trying to use this code below, but dont works :c ...

B4X:
Public Sub Filter(req As ServletRequest, resp As ServletResponse) As Boolean
    Log("requested url : "&req.RequestURI)
    Log("method : "&req.Method)
    resp.Write("intercept www_folder call")
    Return True
End Sub
 
Upvote 0

Waldemar Lima

Well-Known Member
Licensed User
Longtime User
You will break all resources. You are adding a string at the beginning of each resource.
my intention is to take the page being loaded, send it to a php-standalone processor and return the processed page to the filter and display it without having to create a handler, is this possible?
 
Upvote 0

Waldemar Lima

Well-Known Member
Licensed User
Longtime User
Why is this strange requirement not to create a handle?
It was just an idea I had, regarding adding other web language processors, I thought it would be much easier to add in JServer, than creating a wrapper for apache or Xampp..
 
Upvote 0

Waldemar Lima

Well-Known Member
Licensed User
Longtime User
You haven't answered my question. Why don't you want to create a handler? Where do you want to write the code if not with a handler?

ooh, sorry for misunderstanding, I would like to capture the pages requested by the users, if it is a page with a .php or .lua extension, I want to get the content of the file, send it to an external processor and return to the user only the processed html and js.

1642528813964.png
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
B4X:
Public Sub Filter(req As ServletRequest, resp As ServletResponse) As Boolean
    Log(req.RequestURI)
    If req.RequestURI.EndsWith(".txt") Then
        Dim s As String = File.ReadString(File.Combine(Main.srvr.StaticFilesFolder, req.RequestURI), "")
        s = s & " modified by MonitorFilter"
        resp.Write(s)
        Return False
    End If
    Return True
End Sub

And you will need this if you want to make a http request from the server: https://www.b4x.com/android/forum/threads/server-jokhttputils2-server-version.124350/#content
 
Upvote 0
Top