Jump to content
Yaron

Responding to unspecified entry paths

Recommended Posts

Is it possible to make a sort of "catch all" for all "GET/POST" commands that use a path not specified through mars?

 

For example, I have mars specified to return a page using "http://website.com/rest/info"

However, If the client opens the unspecified "http://website.com/rest/none" path, MARS throws an exception.

 

Instead of the exception, I want to catch all unspecified paths and return an HTML result (and keep a record of the unspecified path in my debug logs).

 

Is this possible?

Edited by Yaron

Share this post


Link to post

Hi @Yaron,

you can register an InvokeError procedure to deal with non-matching URLs, there's a template in Server.Ignition file, line 107 (https://github.com/andrea-magni/MARS/blob/daef64912b04036917cb336c4eee34438fa993a8/Demos/MARSTemplate/Server.Ignition.pas#L107).

 

If you uncomment that registration, you can implement whatever policy using the AActivation argument to access Request and Response objects (you can set the StatusCode, Content and ContentType of the Response object as you like).

 

Sincerely,

Andrea

  • Like 1

Share this post


Link to post

I'm using AJAX forms with javascript's "history.pushState" to preserve the browser's "back" button functionality.

 

So if my entry point is "https://myserver.com/v/site/", clicking on a link would look like "https://myserver.com/v/site/page1/" without any actual page being loaded (only part of the page).

 

My problem is that when the user tries to refresh the page, MARS won't recognize the "https://myserver.com/v/site/page1/" path.  In reality, I would like to redirect such URLs back to "https://myserver.com/v/site/".

 

I tried registering the InvokeError procedure like this:

    TMARSActivation.RegisterInvokeError(
      procedure (const AActivation: IMARSActivation; const AException: Exception; var AHandled: Boolean)
      begin
        ShowMessage(AActivation.Request.URL);
        AHandled := True;
      end
    );

Which is triggered, but "AActivation.Request.URL" returns an empty string and I'm not sure how to perform the redirect...  can you help?

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×