Yoctol/bottender

less greedy request handler?

dcsan opened this issue · 2 comments

dcsan commented

Is your feature request related to a problem? Please describe.

currently the request handler takes all routes *
I'm just running a slack bot.

  // route for webhook request
  server.all('*', (req, res) => {
    return handle(req, res);
  });

I want to also serve a react app on the same express/ setup
because of the way client side routes work it's also best to use a * for serving these.

https://create-react-app.dev/docs/deployment/#serving-apps-with-client-side-routing

so the solution I think is to just pass specific named routes to bottender:

  server.all('/webhooks/slack', (req, res) => {
    return handle(req, res);
  });

I think this works ok... but I'm not sure if handle() is expecting the route to be named, or if it defines the route itself assuming it's mounted at /

Describe the solution you'd like
A bit more info on combining botTender express and other tools would be helpful.

Describe alternatives you've considered
nginx reverse proxies. But I hit other problems there :(

You could use /webhooks/* instead:

server.all('/webhooks/*', (req, res) => {
  return handle(req, res);
});

server.get('/*', function (req, res) {
  res.sendFile(path.join(__dirname, 'build', 'index.html'));
});

And you must make sure all of your path in your bottender.config.js file starts with /webhooks to keep it working:

  channels: {
    slack: {
      enabled: ${platforms.includes('slack')},
      path: '/webhooks/slack',
      accessToken: process.env.SLACK_ACCESS_TOKEN,
      signingSecret: process.env.SLACK_SIGNING_SECRET,
    },
  },

@dcsan Does this approach work in your case?