hapijs / hapi

The Simple, Secure Framework Developers Trust

Home Page:https://hapi.dev

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Bun – POST request returns 500 status code

raphael-papazikas opened this issue · comments

Support plan

  • is this issue currently blocking your project? (yes/no): no
  • is this issue affecting a production system? (yes/no): no

Context

  • node version: bun 1.x
  • module version with issue: 21.3.x
  • last module version without issue: -
  • environment (e.g. node, browser, native): bun
  • used with (e.g. hapi application, another framework, standalone, ...): hapi application
  • any other relevant information: –

What are you trying to achieve or the steps to reproduce?

Experimenting with bun.

import * as Hapi from '@hapi/hapi';

// this is necessary, because bun does not support this perf_hooks api right now
// <https://github.com/oven-sh/bun/issues/5804>
const PerfHooks = require('perf_hooks');
PerfHooks.performance.eventLoopUtilization = function() {}

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

    server.route({
        path: "/api/test",
        method: "POST",
        handler: function() {
            console.log("successful")
            return {status: "ok"}
        }
    })

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

init();

Steps to reproduce

  • Install bun: https://bun.sh/
  • Install dependencies: bun install --backend=copyfiles
  • Run server bun run index.ts
  • Now you should see Server running on http://localhost:4000
  • Now run a curl request to the recently added endpoint:
curl --request POST \
  --url http://localhost:4000/api/test \
  --header 'Content-Type: application/json' \
  --data '{}'

What was the result you got?

Received 500 status code from the server. Seems like it throws through this line in wreck:
https://github.com/hapijs/wreck/blob/f53808548f8253c194da0f32ac9ae3d986e86d79/lib/index.js#L434 => https://github.com/hapijs/wreck/blob/f53808548f8253c194da0f32ac9ae3d986e86d79/lib/index.js#L429C18-L429C18

What result did you expect?

I would expect the same behavior as for node environment

@raphael-papazikas If a nodejs replica doesn't run Hapi, but Hapi runs in anything Node 16+, then it's not Hapi, it's the nodejs replica. I think the onus is on you guys to find out where the issue lies and report it to the Bun team. You may be solving a critical problem where Bun does not in fact behave like NodeJS.

Unable to repro today on Bun 1.1.10 & @hapi/hapi version 21.3.9

Server code above prints "successful" and curl response is {"status":"ok"}

@reedspool @raphael-papazikas seems like this is no longer an issue with newer versions of Bun.