Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix derby/server cluster imports #635

Merged
merged 2 commits into from
May 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading