Skip to content

Commit

Permalink
solidify url building strategy
Browse files Browse the repository at this point in the history
  • Loading branch information
copleykj committed Jun 5, 2024
1 parent da5a0f9 commit c9dd453
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions server.jsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
import { FastRender } from 'meteor/communitypackages:fast-render';
import { Headers, Request } from 'meteor/fetch';

import React, { StrictMode } from 'react';
import { Helmet } from 'react-helmet';
import { createRoutesFromElements } from 'react-router-dom';
import { StaticRouterProvider, createStaticHandler, createStaticRouter } from 'react-router-dom/server';
import { renderToString } from 'react-dom/server';
// these 2 imports just silence warnings from the check-npm-versions package because the
// imports above have / server at the end and meteor won't bundle the package.json file for these.
import 'react-dom';
import AbortController from 'abort-controller';
import { isAppUrl } from './helpers';
// This import just silences warnings from the check-npm-versions package because the
// import above has /server at the end and meteor won't bundle the package.json file for these.
import 'react-dom';
import './version-check';

const helmetTags = [
Expand Down Expand Up @@ -82,10 +81,14 @@ function createFetchRequest (sink) {
signal: controller.signal,
};

const href = url.href;
const host = sinkHeaders['x-forwarded-host'];
const proto = sinkHeaders['x-forwarded-proto'];

const newUrl = new URL(`${proto}://${host}${href}`);
const baseUrl = getBaseUrlFromHeaders(sinkHeaders);
const fullUrl = `${baseUrl}${url.pathname || ''}`;
const newUrl = new URL(fullUrl);
return new Request(newUrl, init);
};

const getBaseUrlFromHeaders = headers => {
const protocol = headers['x-forwarded-proto'];
const { host } = headers;
return `${protocol ? `${protocol}:` : ''}//${host}`;
};

0 comments on commit c9dd453

Please sign in to comment.