Advertisement
Guest User

Untitled

a guest
Mar 11th, 2020
317
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. static async getInitialProps({ Component: { getInitialProps }, ctx }) {
  2.     const pageProps = await (async () =>
  3.       getInitialProps ? await getInitialProps(ctx) : {})();
  4.     const { req, res, asPath, query, pathname: ctxPathname } = ctx;
  5.  
  6.     handleRedirect({ res, query });
  7.  
  8.     const userAgent = req ? req.headers['user-agent'] : navigator.userAgent;
  9.     // @TODO: Review this change on FE_URL constant, due to SSR proxy
  10.     // const hostname = req ? req.get('host') : window.location.hostname;
  11.     // const host = req ? req.get('Host') : window.location.host;
  12.     // const protocol = req ? `${req.protocol}:` : window.location.protocol;
  13.     // const origin = `${protocol}//${host}`;
  14.     const { protocol, host, hostname, origin } = new Url(FE_URL);
  15.     const { pathname, query: urlQuery } = new Url(asPath, true);
  16.     const href = origin + asPath;
  17.  
  18.     return {
  19.       pageProps,
  20.       origin,
  21.       url: {
  22.         protocol,
  23.         href,
  24.         hostname,
  25.         host,
  26.         origin,
  27.         pathname,
  28.         query: urlQuery,
  29.       },
  30.       userAgent,
  31.       asPath,
  32.       pathname: ctxPathname,
  33.       query,
  34.     };
  35.   }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement