-
Notifications
You must be signed in to change notification settings - Fork 0
/
load-context.ts
39 lines (32 loc) · 935 Bytes
/
load-context.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
import { type AppLoadContext } from '@remix-run/cloudflare';
import { type ConsolaInstance } from 'consola';
import { type PlatformProxy } from 'wrangler';
import { HashnodeAgent } from './app/services/api/hashnode-agent';
import { logger } from './app/services/libs/logger';
type Cloudflare = Omit<PlatformProxy<Env>, 'dispose'>;
declare module '@remix-run/cloudflare' {
interface AppLoadContext {
cloudflare: Cloudflare;
env: Env;
agent: HashnodeAgent;
logger: ConsolaInstance;
}
}
type GetLoadContext = (args: {
request: Request;
context: { cloudflare: Cloudflare };
}) => AppLoadContext;
export const getLoadContext: GetLoadContext = ({ context }) => {
const { cloudflare } = context;
const bindings = cloudflare.env;
const agent = new HashnodeAgent({
service: bindings.API_BASE_URL,
prefix: '/api/v1',
});
return {
...context,
env: bindings,
agent,
logger,
};
};