简体   繁体   English

Kraken.js为静态文件设置maxAge

[英]Kraken.js set maxAge for static files

I'm trying to set the max-age for static files using Kraken.js (Express.js/Node.js) 我正在尝试使用Kraken.js(Express.js / Node.js)设置静态文件的最大使用期限

I use to edit app.use(express.static(__dirname + '/public', { maxAge: oneDay }) to set this, but it looks like it is not available anymore. 我用来编辑app.use(express.static(__dirname + '/public', { maxAge: oneDay })进行设置,但是看起来不再可用。

Help would be greatly appreciated! 帮助将不胜感激!

The maxAge option is still available in express' static middleware. 在express的static中间件中maxAge选项仍然可用

Assuming you're using kraken >= v1.0, serving static assets is handled for you by default. 假设您使用的是kraken> = v1.0,则默认情况下会为您处理投放静态资产。 I cannot be certain without looking at your code but it's highly likely your app.use(express.static ... isn't actually doing anything since, again, kraken defaults to serving up your static assets for you. Try removing it and seeing if your static assets are still being served up. 我无法确定是否不看您的代码,但是您的app.use(express.static ...实际上没有做任何事情,因为kraken再次默认为您提供静态资产。请尝试删除它并查看如果您的静态资产仍在使用中。

If that's the case, you'll want to set the maxAge config inside your config/config.json (or config/development.json if you want to have a different value in development). 如果是这种情况,您将需要在config/config.json (如果要在开发中使用其他值,则可以在config/development.json设置maxAge配置。

This is what that would look like in your config ( 864e5 being the number of ms in a day): 这就是您的配置中的样子( 864e5是一天中的毫秒数):

{
    "middleware": {
        "static": {
            "module": {
                "name": "serve-static",
                "arguments": [
                    "path:./public",
                    { "maxAge": 864e5 }
                ]
            }
        }
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM