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

Middleware unable to be used by Express router #12

Open
mikecbrant opened this issue Jul 27, 2018 · 1 comment
Open

Middleware unable to be used by Express router #12

mikecbrant opened this issue Jul 27, 2018 · 1 comment

Comments

@mikecbrant
Copy link

Was trying to use this module to apply different default cache control settings on two Express routers mounted on an app, and it seem this use case is not supported (perhaps because of (odd?) way that the modules exposes a function the returns a named function?)

My code looked like:

const cacheControl = require('express-cache-controller');
...
apiRouter.use(cacheControl({ [options] });
...
mainRouter.use(cacheControl({ [options] });

This did not work and there was not any sort of error triggered. My routers just simply did not apply the correct headers.

I tried other alternatives like:

const cacheControlInit = require('express-cache-controller');
...
apiRouter.use(cacheControlInit ({ [options] });
...
mainRouter.use(cacheControlInit ({ [options] });

and:

require('express-cache-controller')({ [options] });
...
apiRouter.use(cacheControl);
...
mainRouter.use(cacheControl);

but wasn't able to get to work until finally just doing:

const cacheControl = require('express-cache-controller');
...
app.use(cacheControl({ [options] });

Figured I would open an issue, as it would be unexpected behavior IMO middleware to not work on a router.

I also think it would be extremely helpful to include information on how to properly require the module in your documentation. I saw there was an old closed issue about this, but the documentation doesn't show this. It would have probably saved some time in me fiddling around with various approaches to including this module.

@martinszy
Copy link

This is a good point with no response. Is this project abandoned?

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