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

less greedy request handler? #836

Open
dcsan opened this issue Jul 11, 2020 · 2 comments
Open

less greedy request handler? #836

dcsan opened this issue Jul 11, 2020 · 2 comments
Labels

Comments

@dcsan
Copy link

dcsan commented Jul 11, 2020

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 :(

@chentsulin
Copy link
Collaborator

chentsulin commented Jul 11, 2020

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,
    },
  },

@chentsulin
Copy link
Collaborator

@dcsan Does this approach work in your case?

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

No branches or pull requests

2 participants