ndaidong
ndaidong
HHono
Created by ndaidong on 9/4/2024 in #help
How to work with node:cluster in Bun?
I tried to test hono with node:cluster module that has just been added to Bun v1.2.25 Here are my scripts: server.js
import { Hono } from 'hono'

const app = new Hono()
app.get('/', (c) => c.text('Hello Bun!'))

export default {
port: 3000,
// reusePort: true, // I also tested with this option but no effect
fetch: app.fetch,
}
import { Hono } from 'hono'

const app = new Hono()
app.get('/', (c) => c.text('Hello Bun!'))

export default {
port: 3000,
// reusePort: true, // I also tested with this option but no effect
fetch: app.fetch,
}
And cluster.js
import cluster from 'node:cluster'
import { cpus } from 'node:os'

if (cluster.isPrimary) {
for (let i = 0; i < cpus().length; i++) {
cluster.fork()
}
} else {
import('./server.js')
}
import cluster from 'node:cluster'
import { cpus } from 'node:os'

if (cluster.isPrimary) {
for (let i = 0; i < cpus().length; i++) {
cluster.fork()
}
} else {
import('./server.js')
}
Then I ran bun run server.js and access http://localhost:3000 --> it works. But when I started cluster mode with bun run cluster.js, the script seems work but I could not access the HTTP server. All the following targets are unaccessible: - http://localhost:3000 - http://127.0.0.1:3000 - http://0.0.0.0:3000
1 replies