[英]Express: Disable headers for specific routes (Etag, set-cookie, etc)
For my application, we have rest API and the webapp server from the same app.对于我的应用程序,我们有来自同一个应用程序的 rest API 和 webapp 服务器。 (it is small enought not to have separate deployment) (小到没有单独部署)
Is there any way I can exclude all /api/*
route paths to disable caching and cookies?有什么办法可以排除所有/api/*
路由路径以禁用缓存和 cookie?
Note: I cannot do app.disable('etag')
as it will disable for the entire webapp.注意:我不能做app.disable('etag')
因为它会禁用整个 webapp。
Afaik this is currently not possible - also there are a few open issues on github like this one for example: https://github.com/expressjs/express/issues/2472 Afaik 这目前是不可能的 - 在 github 上也有一些未解决的问题,例如: https : //github.com/expressjs/express/issues/2472
As a workaround you could remove the headers for requests on the /api
-route using something like this:作为一种解决方法,您可以使用以下内容删除/api
-route 上请求的标头:
const onHeaders = require('on-headers')
// mount custom middleware for all api-requests
app.use("/api*", (req, res, next) => {
removeHeaders(res);
next();
});
function removeHeaders(res) {
onHeaders(res, () => {
res.removeHeader('ETag');
// remove other headers ...
});
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.