Skip to content
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 javascript/bun/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules/
21 changes: 21 additions & 0 deletions javascript/bun/bun.lock
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not needed ;-)

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 29 additions & 0 deletions javascript/bun/cluster.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import cluster, { type Worker } from 'node:cluster';

function startServer() {
const server = Bun.serve({
hostname: '0.0.0.0',
port: 3000,
reusePort: true,
development: false,
routes: {
'/': () => new Response(null, { status: 204 }),
'/user': () => new Response(null, { status: 204 }),
'/user/:id': ({ params }) => new Response(params.id, { status: 200 }),
},
});

console.debug(`Worker PID: ${process.pid} listening on ${server.url}`);
}

function forkWorkers() {
console.log(`Primary PID: ${process.pid}`);
for (let i = 0; i < navigator.hardwareConcurrency; i++) cluster.fork();

cluster.on('exit', (worker, code, signal) => {
console.error(`Worker PID: ${worker.process.pid} died with code ${code} and signal ${signal}`);
});
}

if (cluster.isPrimary) forkWorkers();
else startServer();
6 changes: 6 additions & 0 deletions javascript/bun/config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
framework:
github: oven-sh/bun
version: 1.2.5
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
version: 1.2.5
version: 1.2


engines:
- bun
5 changes: 5 additions & 0 deletions javascript/bun/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"devDependencies": {
"@types/bun": "^1.2.5"
}
}
Loading