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

HyperExpress doesn't support very useful next function in its methods #198

Closed
dimdenGD opened this issue Nov 11, 2023 · 3 comments
Closed

Comments

@dimdenGD
Copy link

Code similar to #197 but entirely different issue:

import express from 'express';
import HyperExpress from 'hyper-express';

const USE_HYPER_EXPRESS = true;

const app = USE_HYPER_EXPRESS ? new HyperExpress.Server() : express();

app.get('/', (req, res) => {
    res.send('Hello World!');
});

app.get('/:name', (req, res, next) => {
    if(req.params.name === 'tester') {
        return next();
    }
    res.send(`Hello ${req.params.name}!`);
});

app.get('/:name2', (req, res) => {
    res.send(`Greetings, ${req.params.name2}.`);
});

if(USE_HYPER_EXPRESS) {
    app.listen(3001)
        .then(() => {
            console.log('Listening on port 3001');
        }).catch((err) => {
            console.error(err);
        });
} else {
    app.listen(3001, () => {
        console.log('Listening on port 3001');
    });
}

If you use express:

  • Going to localhost:3001/test will return Hello test!
  • Going to localhost:3001/tester will return Greetings, tester.

If you use hyper-express:

  • Going to localhost:3001/test will return Hello test!
  • Going to localhost:3001/tester will return HyperExpress: Uncaught Exception Occured (TypeError: next is not a function)
@kartikk221
Copy link
Owner

I see, so this behavior seems to occur because Express allows usage of overlapping routes while uWebsockets.js the underlying performant webserver that powers hyper-express will serve the first route it matches natively.

With that said, adding support for this should not be too difficult given hyper-express can simply match overlapping routes, then execute the first one and provide a next() iterator which lets you chain multiple routes similar to middlewares throughout the request lifecycle.

I will begin exploring an implementation for this feature and potentially have it rolled out soon.

@kartikk221
Copy link
Owner

Closing for now as addressed in #197

@dimdenGD
Copy link
Author

Hi, are you still working on this? I don't believe this and #197 should have been closed since they're ongoing issues. These issues are one of the biggest roadblocks in using this library, would be really nice to see these reopened and fixed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants