Base routes are always empty with rendertron

220 Views Asked by At

I have been trying to use rendertron through an apache proxy, but all the base routes are "null", is it possible that I am making some configuration error? I would appreciate if you could help me.

Rendertron is running on port 3000 that has by default. and the apache host is this:

<VirtualHost *:80>
        ServerName render.vool.xyz
        ProxyRequests Off

  <Proxy *>
     #Require all granted
     Order deny,allow
     Allow from all
  </Proxy>

  <Location />
        ProxyPass http://localhost:3000/
        ProxyPassReverse http://localhost:3000/
        Header set Access-Control-Allow-Origin "http://render.vool.xyz"
  </Location>
</VirtualHost>

Rendertron service is up and running in the render.vool.xyz url

Thanks again

1

There are 1 best solutions below

0
Michael Sanchez On

I could detect that a slash corresponding to the protocol in the initialization is removed from the url

this.app.use(
       route.get('/render/:url(.*)', this.handleRenderRequest.bind(this)));

I solved it by adding the following method in the rendertron class and calling it from the handleRenderRequest method

handleFixProtocol(href: string) {
    if (href.startsWith('https://') || href.startsWith('https://') ) {
      return href;
      } else {
        const parsedUrl = url.parse(href);
        if (!parsedUrl.host) {
          return parsedUrl.protocol + '/' + parsedUrl.path;
        } else {
          return parsedUrl.protocol + '//' + parsedUrl.host + parsedUrl.path;
        }
    }
   }
async handleRenderRequest(ctx: Koa.Context, url: string) {
    if (!this.renderer) {
      throw (new Error('No renderer initalized yet.'));
    }

    url = this.handleFixProtocol(url);