Skip to content

Commit

Permalink
Adding a cache-control header with the value of public, max-age=n
Browse files Browse the repository at this point in the history
… for static assets served for browsable interface, upgrades server
  • Loading branch information
avoidwork committed May 18, 2017
1 parent 14eee77 commit c734f27
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 4 deletions.
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,15 @@ The browsable template can load assets from this folder. assets.
}
```

## Static assets cache
The browsable template assets have a default `public` cache of `300` seconds (5 minutes). These assets will always be considered `public`, but you can customize how long they are cacheable.

```
{
"staticCache": 300
}
```

## License
Copyright (c) 2017 Jason Mulligan
Licensed under the BSD-3-Clause license.
3 changes: 2 additions & 1 deletion config.json
Original file line number Diff line number Diff line change
Expand Up @@ -130,5 +130,6 @@
"hypermedia": "[a-zA-Z]+_(guid|uuid|id|url|uri)$",
"id": "^(_id|id)$"
},
"static": "/assets/.*"
"static": "/assets/.*",
"staticCache": 300
}
6 changes: 5 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,11 @@ function factory (arg) {
config.routes.get = {};
}

config.routes.get[config.static] = (req, res) => req.server.static(req, res);
config.routes.get[config.static] = (req, res) => {
res.header("cache-control", "public, max-age=" + (config.staticCache || 300));
req.server.static(req, res);
};

config.root = path.resolve(config.root);
config.template = fs.readFileSync(config.template || path.join(config.root, "template.html"), {encoding: "utf8"});
config.version = pkg.version;
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "tenso",
"description": "Tensō is an elastic REST API gateway for node.js",
"version": "4.5.0",
"version": "4.5.1",
"homepage": "http://avoidwork.github.io/tenso",
"author": "Jason Mulligan <[email protected]>",
"repository": {
Expand Down Expand Up @@ -45,7 +45,7 @@
"tiny-merge": "~1.0.0",
"tiny-uuid4": "~1.0.1",
"tiny-xml": "~1.0.6",
"turtle.io": "~7.5.10",
"turtle.io": "~7.5.11",
"uws": "~0.14.1",
"yamljs": "~0.2.10"
},
Expand Down

0 comments on commit c734f27

Please sign in to comment.