Giter VIP home page Giter VIP logo

elysia-polyfills's People

Contributors

bogeychan avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

elysia-polyfills's Issues

Cors issue in node 20

When using node 20 with Elysia, @elysiajs/cors and @bogeychan/elysia-polyfills/node/index.js, we get an error with the 204 response.

Response constructor: Invalid response status code 204

I have tracked it down to the Elysia plugin, changing the Response from

            return new Response('', {
                status: 204
            });

to the following fixes it.

            return new Response(null, {
                status: 204
            });

I am opening the issue in this repo as it probably should be fixed in the polyfills, and not in the Bun only repo.

TypeError: this.server.reload is not a function

Elysia calls this.server.reload() here whenever .use() is called:

https://github.com/elysiajs/elysia/blob/9192fa90c57467a3f60fe6c5e8963e89a994a2bc/src/index.ts#L2716

This results in this runtime error:

TypeError: this.server.reload is not a function
    at Elysia.compile (node_modules/elysia/dist/cjs/index.js:518:25)

Workaround

I worked around this issue from the userland by monkey-patching Bun.server to add a no-op .reload() function to the server instance.

import '@bogeychan/elysia-polyfills/node/index.js'

const originalServe = globalThis.Bun.serve

// Implement server.reload() function. Otherwise, Elysia may crash with:
//
// TypeError: this.server.reload is not a function
//     at Elysia.compile (node_modules/elysia/dist/cjs/index.js:518:25)
//
globalThis.Bun.serve = function (...args) {
    const server = originalServe.apply(this, args as any)
    if (!server.reload) {
        server.reload = () => {}
    }
    return server
}

`response.headers.toJSON is not a function` when trying to return `new Response("foo")` with serverTIming plugin enabled

With [email protected] when trying to return any kind of raw response (including the swagger plugin that returns a raw response for the swagger page), as long as the server timing plugin is enabled, it will return the following error:

error: TypeError: response.headers.toJSON is not a function
      at mapResponse (/Users/blucky/git/work-sst/node_modules/.pnpm/[email protected]_@[email protected][email protected]/node_modules/elysia/dist/cjs/handler.js:134:52)
      at handle (eval at composeHandler (/Users/blucky/git/work-sst/node_modules/.pnpm/[email protected]_@[email protected][email protected]/node_modules/elysia/dist/cjs/compose.js:1151:27), <anonymous>:85:8)
      at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
      at async Server.handler (file:///Users/blucky/git/work-sst/node_modules/.pnpm/@[email protected][email protected]/node_modules/@bogeychan/elysia-polyfills/dist/mjs/env/node/server.js:34:35)

disabling the plugin makes it work properly

I know the server timing plugin isn't even on the chart in the README.md, but this seems like an easy enough fix potentially, just putting a .toJSON = (self)=>JSON.stringify(self) or something in the right place, so I figured I'd report it anyway

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.