Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SSR] pass request headers to ssr server #665

Open
MordiSacks opened this issue Sep 30, 2024 · 2 comments
Open

[SSR] pass request headers to ssr server #665

MordiSacks opened this issue Sep 30, 2024 · 2 comments

Comments

@MordiSacks
Copy link

It would be great if the HttpGateway will forward the original http context (headers, ip, etc) to the ssr renderer.

This would unlock client dependent opportunities (mobile detection, regional specific content, etc.) .

@RobertBoes
Copy link
Contributor

Could you elaborate on why this is helpful and how this would work? I'm having a hard time understanding how this would work, while I get the value of it.

To be clear; Inertia's SSR would only render the HTML of the initial request, so it would only render HTML once, after that it's all CSR. This is useful for search engines and an optimization for load times. However, if you're conditionally rendering things based on the headers, that wouldn't work client-side, because that also doesn't receive request headers

@MordiSacks
Copy link
Author

Let's look at view port for example

useViewPort.js

import {onMounted, reactive} from 'vue';

// no request context
const vp = reactive({w: 0, h: 0});

// with request context
const vp = reactive({w: parseUserAgent(req.headers.userAgent).type === 'mobile' ? 400 : 1024, h: 0});

export default function useViewPort() {
  if (typeof window !== 'undefined') onMounted(async () => {
    vp.w = window.innerWidth;
    vp.h = window.innerHeight;

    window.addEventListener('resize', () => {
      vp.w = window.innerWidth;
      vp.h = window.innerHeight;
    });
  });

  return vp;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants