-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.ts
36 lines (31 loc) · 867 Bytes
/
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
import { createRequestHandler } from "@remix-run/express";
import { broadcastDevReady, installGlobals } from "@remix-run/node";
import express from "express";
import * as build from "@remix-run/dev/server-build";
import { auth, csrfProtection } from "./auth";
// patch in Remix runtime globals
installGlobals();
const app = express();
app.use(express.static("public"));
// CSRF protection
app.use(csrfProtection);
// and your app is "just a request handler"
app.all(
"*",
createRequestHandler({
build,
getLoadContext: async (request, response) => {
const { session, user } = await auth(request, response);
return {
session,
user,
};
},
})
);
app.listen(3000, () => {
if (process.env.NODE_ENV === "development") {
broadcastDevReady(build);
}
console.log("App listening on http://localhost:3000");
});