I am a lover of beautiful and short code, and here a problem arises ... short of course, but not beautiful. Can this code be made more beautiful?
app.post('/xsolla/', (req, res) => new Xsolla(req, res));
tried this option but it didn't work😅
app.post('/xsolla/', new Xsolla);
One option is to use rest parameters instead of repeating them:
app.post('/xsolla/', (...args) => new Xsolla(...args));
But keep in mind that readable code is more important than short code.
Reflect.construct (in combination with .bind) would almost do the trick for removing the need to list arguments altogether, but unfortunately it takes the arguments to be passed to the constructor as an array in the second argument, rather than as separate items in the argument list.
If you were doing this in multiple places and just wanted to avoid repeated code, you could make yourself a reusable request handler:
function xHandler(req, res) {
new Xsolla(req, res);
}
app.post('/xsolla/', xHandler);