Skip to content
Open
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
11 changes: 4 additions & 7 deletions bench.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import {
readdirSync,
mkdirSync,
existsSync,
lstatSync,
mkdirSync,
readdirSync,
readFileSync,
writeFileSync
} from 'fs'
import killPort from 'kill-port'
import { $, pathToFileURL } from 'bun'

const whitelists = <string[]>[]

Expand All @@ -17,8 +16,6 @@ const blacklists = [
'node/adonis/index',
// Not setting content-type header for some reason
'node/nest/index',
// 'Not booting up in test'
'node/hapi',
// Body: Result not match
'bun/xirelta',
// Crash
Expand Down Expand Up @@ -50,7 +47,7 @@ const commands = [

const runtimeCommand = {
node: 'node',
deno: 'deno run --allow-net --allow-env',
// deno: 'deno run --allow-net --allow-env',
bun: 'bun'
} as const

Expand Down Expand Up @@ -154,7 +151,7 @@ const spawn = (target: string, title = true) => {
: `src/${runtime}/${framework}.js`

const server = Bun.spawn({
cmd: [...runtimeCommand[runtime].split(" "), file],
cmd: [...runtimeCommand[runtime].split(' '), file],
env: {
...Bun.env,
NODE_ENV: 'production'
Expand Down
45 changes: 45 additions & 0 deletions src/bun/hapi.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
const Hapi = require('@hapi/hapi')

const init = async () => {
const server = Hapi.server({
port: 3000,
host: 'localhost'
})

server.route([
{
method: 'GET',
path: '/',
handler: (request, h) => {
const res = h.response('Hi')
res.type('text/plain')
return res
}
},
{
method: 'POST',
path: '/json',
handler: (request, h) => h.response(request.payload)
},
{
method: 'GET',
path: '/id/{id}',
handler: (request, h) => {
const res = h.response(
`${request.params.id} ${request.query.name}`
)
res.type('text/plain')
res.header('x-powered-by', 'benchmark')
return res
}
}
])

await server.start()
console.log('Server running on %s', server.info.uri)
}

init().catch((error) => {
console.error(error)
process.exit(1)
})
32 changes: 20 additions & 12 deletions src/node/hapi.js
Original file line number Diff line number Diff line change
@@ -1,34 +1,42 @@
const Hapi = require("@hapi/hapi")
const Hapi = require('@hapi/hapi')

const init = async () => {
const server = Hapi.server({
port: 3000,
host: "localhost"
host: 'localhost'
})

server.route([
{
method: "GET",
path: "/",
handler: (request, h) => "Hi"
method: 'GET',
path: '/',
handler: (request, h) => {
const res = h.response('Hi')
res.type('text/plain')
return res
}
},
{
method: "POST",
path: "/json",
method: 'POST',
path: '/json',
handler: (request, h) => h.response(request.payload)
},
{
method: "GET",
path: "/id/{id}",
method: 'GET',
path: '/id/{id}',
handler: (request, h) => {
response.header("x-powered-by", "benchmark")
return h.response(`${request.params.id} ${request.query.name}`)
const res = h.response(
`${request.params.id} ${request.query.name}`
)
res.type('text/plain')
res.header('x-powered-by', 'benchmark')
return res
}
}
])

await server.start()
console.log("Server running on %s", server.info.uri)
console.log('Server running on %s', server.info.uri)
}

init().catch((error) => {
Expand Down