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

Feature request: middleware #13

Closed
TigersWay opened this issue Mar 12, 2022 · 5 comments
Closed

Feature request: middleware #13

TigersWay opened this issue Mar 12, 2022 · 5 comments
Labels
documentation Improvements or additions to documentation

Comments

@TigersWay
Copy link

I have been using - quite a lot - the middleware feature of browsersync.

Despite being "minimal", could this new server propose the same feature?
Of course it's still possible to use browsersync.

@zachleat
Copy link
Member

This exists, though it hasn’t been added to the docs yet. Here’s the 2.0 canary serverless plugin using it: https://github.com/11ty/eleventy/blob/85b8a916245f0343dce9cda4ee268d41df2c6bf1/src/Plugins/ServerlessBundlerPlugin.js#L321

@zachleat zachleat added the documentation Improvements or additions to documentation label Mar 14, 2022
@TigersWay
Copy link
Author

I'm going to try it today then!! 👍

@TigersWay
Copy link
Author

Sorry I haven't had so much time to check.... but my own middleware gives

[11ty] Unhandled rejection in promise: (more in DEBUG output)
[11ty] ware.bind is not a function (via TypeError)
[11ty]
[11ty] Original error stack trace: TypeError: ware.bind is not a function
[11ty]     at EleventyDevServer.onRequestHandler......

it may be on my side, but I have no trouble with browser-sync in Eleventy - old or new versions.

@zachleat
Copy link
Member

Ahhhh, yeah I don’t think we support object for middleware. Only functions right now!

 middleware: [{
      route: '/img',
      handle: require('browsersync-images-middleware')('public')
    }],

That said I believe you can refactor it to use a function instead:

function(req, res, next) {
  if(!req.url.startsWith("/img")) {
    next();
  }
  // do the thing
}

@TigersWay
Copy link
Author

You're right I could refactor... But I believe I'm the only one using my own middleware 😬 and as browser-sync went back to an ok status, I won't bother.
Thanks anyway for your checking!

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

No branches or pull requests

2 participants