From a4f64b3e160766d521f1fe2d95ee2e9d6362c51a Mon Sep 17 00:00:00 2001 From: Tyler Hall <0tillathehun0@gmail.com> Date: Tue, 24 May 2022 14:05:59 +0000 Subject: [PATCH] feat(remix-serve): allow passing getLoadContext for programattically starting server --- packages/remix-serve/index.ts | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/packages/remix-serve/index.ts b/packages/remix-serve/index.ts index 2072474695a..5b54be58b54 100644 --- a/packages/remix-serve/index.ts +++ b/packages/remix-serve/index.ts @@ -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"); @@ -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 + ); } );