Skip to content

Middleware unable to be used by Express router #12

@mikecbrant

Description

@mikecbrant

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions