-
Notifications
You must be signed in to change notification settings - Fork 281
/
server.ts
51 lines (44 loc) · 1.22 KB
/
server.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import {
createRequestHandler as createRemixRequestHandler,
type AppLoadContext,
type ServerBuild,
} from '@remix-run/server-runtime';
export function createRequestHandler<Context = unknown>({
build,
mode,
poweredByHeader = true,
getLoadContext,
}: {
build: ServerBuild;
mode?: string;
poweredByHeader?: boolean;
getLoadContext?: (request: Request) => Promise<Context> | Context;
}) {
const handleRequest = createRemixRequestHandler(build, mode);
return async (request: Request) => {
const response = await handleRequest(
request,
(await getLoadContext?.(request)) as AppLoadContext,
);
if (poweredByHeader) {
response.headers.append('powered-by', 'Shopify, Hydrogen');
}
return response;
};
}
export function getBuyerIp(request: Request) {
return request.headers.get('oxygen-buyer-ip') ?? undefined;
}
type StorefrontHeaders = {
requestGroupId: string | null;
buyerIp: string | null;
cookie: string | null;
};
export function getStorefrontHeaders(request: Request): StorefrontHeaders {
const headers = request.headers;
return {
requestGroupId: headers.get('request-id'),
buyerIp: headers.get('oxygen-buyer-ip'),
cookie: headers.get('cookie'),
};
}