Skip to content

Commit

Permalink
Import cluster as namespace to avoid transformed default import which…
Browse files Browse the repository at this point in the history
… does not work
  • Loading branch information
craigbeck committed May 15, 2024
1 parent a1db975 commit 085bf0d
Showing 1 changed file with 4 additions and 1 deletion.
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 085bf0d

Please sign in to comment.