Skip to content

Commit

Permalink
feat(remix-serve): allow passing getLoadContext for programattically …
Browse files Browse the repository at this point in the history
…starting server
  • Loading branch information
TillaTheHun0 committed May 24, 2022
1 parent dce27e2 commit 5d59547
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
1 change: 1 addition & 0 deletions contributors.yml
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,7 @@
- therealflyingcoder
- thomasheyenbrock
- thomasrettig
- TillaTheHun0
- tjefferson08
- tombyrer
- toyozaki
Expand Down
19 changes: 16 additions & 3 deletions packages/remix-serve/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,13 @@ import express from "express";
import compression from "compression";
import morgan from "morgan";
import { createRequestHandler } from "@remix-run/express";
import type { GetLoadContextFunction } from "@remix-run/express";

export function createApp(buildPath: string, mode = "production") {
export function createApp(
buildPath: string,
mode = "production",
getLoadContext?: GetLoadContextFunction
) {
let app = express();

app.disable("x-powered-by");
Expand All @@ -21,11 +26,19 @@ export function createApp(buildPath: string, mode = "production") {
app.all(
"*",
mode === "production"
? createRequestHandler({ build: require(buildPath), mode })
? createRequestHandler({
build: require(buildPath),
mode,
getLoadContext,
})
: (req, res, next) => {
// require cache is purged in @remix-run/dev where the file watcher is
let build = require(buildPath);
return createRequestHandler({ build, mode })(req, res, next);
return createRequestHandler({ build, mode, getLoadContext })(
req,
res,
next
);
}
);

Expand Down

0 comments on commit 5d59547

Please sign in to comment.