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 a4f64b3
Showing 1 changed file with 16 additions and 3 deletions.
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 a4f64b3

Please sign in to comment.