URL Rewriter doesnt get invoked after JSVM pre middleware

I have a use case where a JSVM pre middleware contacts an external host to fetch that actual upstream hostname and use it in the URL Rewriter so that the upstream URL is composed with the hostname fetched from the external host (as the response of pre middleware)

I tried the following scenarios and their results, following by a couple of questions:

A. JSVM Pre Middleware + URL Rewriter >> only the pre middleware executes
B. JSVM Post Auth Middleware + URL Rewriter >> only the Rewriter executes
C. URL Rewriter + JSVM Post Middleware >> Both executes… Rewriter first and then the Middleware (as expected). However, this is not applicable/usable for my use case.

Questions:

  1. Why does the URL Rewrite not get executed in Scenario A?
  2. What is the provision through which the URL Rewriter can absorb data from the JSVM pre middleware? Is this possible at all? I understand from this post (Hostname Rewrite from Middlewares) that it is possible with a GRPC plugin to set session metadata, but am not sure if JSVM can enable transporting data from the middleware response to the Rewriter.

Are rich plugins the only way to make use of URL Rewriters for the use case?

I do not get any clue from the following issues and their fixes:

I want to be able to use the response of my Pre Middleware in URL Rewriter.

Ignore this question. My Bad. After spending more time I was able to set the dynamic hostname into one of the session meta data attributes in a Post Middleware (not Pre) JSVM. In the URL Rewriter, I was able to retrieve it using $tyk_meta.attribute_name. According to Scenario B posted earlier, this combination works and the URL rewriter kicked off and did override the proxy target. Hence everything works.