-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.ts
44 lines (39 loc) · 1.23 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
import { createRequestHandler } from "@remix-run/architect";
import * as build from "@remix-run/dev/server-build";
import { services } from "~/services/services";
import { SessionServerFactory } from "~/session.server";
import type { LoaderContext } from "~/types";
if (process.env.NODE_ENV !== "production") {
require("./mocks");
}
export const handler = createRequestHandler({
build,
mode: process.env.NODE_ENV,
getLoadContext(event): LoaderContext {
const serverContext = services();
/**
* Loaders have access to:
* - Business services
* - SessionServer
* - ApiGatewayProxyEvent
*
* Business logic is encapsulated, having access to only itself (see ./services/services.ts).
* This has lots of benefits:
* - Business logic is framework agnostic and can be reused
* - Remix/NextJS/CRA/Preact
* - Vue
* - Svelte
* - CLI :)
*
* - Easier to test business logic (unit tests!)
* - Separation of concerns
*
* For more info, see https://blog.hyper.io/the-perfect-application-architecture/
*/
return {
...serverContext,
event,
SessionServer: SessionServerFactory({ ...serverContext, event } as LoaderContext),
};
},
});