Expose Oxygen headers #1565
Replies: 4 comments 1 reply
-
All incoming |
Beta Was this translation helpful? Give feedback.
-
@davecyen Are you proposing we do something more with these headers, like parse them into a structured object? The raw header values themselves should be accessible like Josh commented. |
Beta Was this translation helpful? Give feedback.
-
The raw oxygen headers aren't there (you can see this in chrome dev tools > network on an oxygen deployed site) |
Beta Was this translation helpful? Give feedback.
-
Related to what Josh commented here. function App({request}: HydrogenRouteProps) {
const oxygenHeaderPrefix = 'oxygen-buyer-';
const context = useRequestContext();
context.location = {};
request.headers.forEach(([value, key]) => {
if (key.startsWith(oxygenHeaderPrefix)) {
context.location[
key
.replace(oxygenHeaderPrefix, '')
.replace(/-([a-z])/g, (_, char) => char.toUpperCase())
] = value;
}
});
return /* ... */;
} Then it can be accessed later anywhere with |
Beta Was this translation helpful? Give feedback.
-
Hydrogen should expose the following Oxygen variables so that they can be proxy'ed from client and server components. This would be impactful for internationalization when the Hydrogen app is hosted on Oxygen.
Long-term it'd be nice to have some type of adaptor that could be set in
hydrogen.config
and passed in server-side, but in the near-term developers could use API routes to parse these via HTTP headers.Beta Was this translation helpful? Give feedback.
All reactions