Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

stop doesn't work and throws an error #1014

Open
ashokgelal opened this issue Jan 14, 2025 · 1 comment
Open

stop doesn't work and throws an error #1014

ashokgelal opened this issue Jan 14, 2025 · 1 comment
Labels
bug Something isn't working

Comments

@ashokgelal
Copy link

What version of Elysia is running?

1.2.0

What platform is your computer?

Darwin 24.1.0 arm64 arm

What steps can reproduce the bug?

I'm using node adapter and when calling stop it throws this.server.stop is not a function error.

Code snippet:

    const app = new Elysia({adapter: node()})
        .listen(3000)
    setTimeout(() => {
        console.log('Stopping server after 5 secs')
        app.stop()
    }, 5000)

What is the expected behavior?

It should stop the server listening to request.

What do you see instead?

UnhandledPromiseRejectionWarning: TypeError: this.server.stop is not a function

Additional information

No response

Have you try removing the node_modules and bun.lockb and try again yet?

yes

@ashokgelal ashokgelal added the bug Something isn't working label Jan 14, 2025
@ViniciusCestarii
Copy link

Hey @ashokgelal, I found that the second parameter of the listen function is a callback that returns a Server object, which can be used to stop the server.

import Elysia from "elysia";
import { node } from "@elysiajs/node";

const app = new Elysia({ adapter: node() }).listen(3000, (server) => {
  setTimeout(() => {
    console.log("Stopping server after 5 seconds");
    server.stop();
  }, 5000);
});

Upon reviewing the code, I noticed that this file isn't enforcing the implementation of the stop method on the Elysia instance. As a result, the node adapter doesn't implement it.

I'm not sure why it's not included in the type definition.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants