diff --git a/bench.ts b/bench.ts index d0121a8..66abc6a 100644 --- a/bench.ts +++ b/bench.ts @@ -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 = [] @@ -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 @@ -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 @@ -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' diff --git a/src/bun/hapi.ts b/src/bun/hapi.ts new file mode 100644 index 0000000..dc66ce2 --- /dev/null +++ b/src/bun/hapi.ts @@ -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) +}) diff --git a/src/node/hapi.js b/src/node/hapi.js index 743f353..dc66ce2 100644 --- a/src/node/hapi.js +++ b/src/node/hapi.js @@ -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) => {