createExpressApp called twice in development
thomaswelton opened this issue · 3 comments
When running in dev mode I can see that the entry.server
file is loaded twice. As a result createExpressApp
is called twice.
This is an issue as if I add express middleware like prometheus metrics they will be registered twice which will throw an error.
Replication steps
- Add some logging above the
createExpressApp
function call. Or inside of theconfigure
option in theentry.server
- See that this is logged twice after restarting the server
@kiliman Thanks for the commit and fix here. See #25 for an alternative approach and discussion.
Screenshot below is using your new code.
This change has prevented configure from being called twice during local dev. However the entry file is still being loaded or called twice.
This will be an issue as we will want to do some async setup before the call to createExpressApp
Something like
const expressApp = express();
await setupGraphServerAndPrommetrics(expressApp);
export const app = createExpressApp({
getExpress: () => expressApp,
unstable_middleware: true,
buildDirectory: 'remix-build',
serverBuildFile: 'index.mjs'
});
Where setupGraphServerAndPrommetrics
would throw an error if it's called twice.
Looking at it, I'd still run into issues during any HMR of the express server as the entry point would be run again anyway.
So I'll need to address that either way.
Does v0.2.7 fix your issue?