Skip to content

Commit

Permalink
Merge pull request #635 from derbyjs/fix-server
Browse files Browse the repository at this point in the history
Fix derby/server cluster imports
  • Loading branch information
craigbeck authored May 16, 2024
2 parents 1c23390 + 085bf0d commit 6c6f397
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"./App": "./dist/App.js",
"./AppForServer": "./dist/AppForServer.js",
"./server": "./dist/server.js",
"./dist/server": "./dist/server.js",
"./Page": "./dist/Page.js",
"./test-utils": "./dist/test-utils/index.js",
"./test-utils/*": "./dist/test-utils/*.js",
Expand Down
5 changes: 4 additions & 1 deletion src/server.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import cluster from 'cluster';
// import as namespace to avoid transform as cluster.default
import * as cluster from 'node:cluster';

const isProduction = process.env.NODE_ENV === 'production';

export function run(createServer: () => void) {
// In production
if (isProduction) return createServer();
// @ts-expect-error imported without default; need type update?
if (cluster.isPrimary) {
console.log('Primary PID ', process.pid);
startWorker();
Expand All @@ -14,6 +16,7 @@ export function run(createServer: () => void) {
}

function startWorker() {
// @ts-expect-error imported without default; need type update?
const worker = cluster.fork();

worker.once('disconnect', function () {
Expand Down

0 comments on commit 6c6f397

Please sign in to comment.