kopia lustrzana https://github.com/badgen/badgen.net
feat: add a cache option (#338)
* feat: add query param `cache` * chore: bump dependencies * chore: bump semver to 7.1.1 * chore: set default cdn cache to 6hrs * chore: better wordingpull/339/head
rodzic
fd3b1d0aff
commit
f2e179e827
|
@ -43,6 +43,11 @@ export default function HomeIntro ({ isFlat = false }) {
|
|||
Custom badge scale
|
||||
<a href='/badge/docker/v1.2.3/blue?icon=docker&scale=2'>e.g.</a>
|
||||
</li>
|
||||
<li>
|
||||
<code>cache</code>
|
||||
Live badge are cached in cdn for 24hrs (86400), you may limit it to a minimum of 5min (300).
|
||||
<a href='/npm/dm/express?cache=600'>e.g.</a>
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
<h3>Advanced usage</h3>
|
||||
|
|
|
@ -13,10 +13,10 @@ type ServeBadgeOptions = {
|
|||
}
|
||||
|
||||
export default function (req: IncomingMessage, res: ServerResponse, options: ServeBadgeOptions) {
|
||||
const { code = 200, sMaxAge = 300, query = {}, params } = options
|
||||
const { code = 200, sMaxAge = 21600, query = {}, params } = options
|
||||
|
||||
const { subject, status, color } = params
|
||||
const { label, labelColor, icon, iconWidth, list, scale } = query
|
||||
const { label, labelColor, icon, iconWidth, list, scale, cache } = query
|
||||
const _icon = resolveIcon(icon, iconWidth)
|
||||
|
||||
// TODO: review usage of list
|
||||
|
@ -33,8 +33,8 @@ export default function (req: IncomingMessage, res: ServerResponse, options: Ser
|
|||
scale: parseFloat(scale || '1'),
|
||||
})
|
||||
|
||||
const cacheControl = `public, max-age=120, s-maxage=${sMaxAge}, stale-while-revalidate=86400`
|
||||
res.setHeader('Cache-Control', cacheControl)
|
||||
const cacheMaxAge = cache ? Math.max(parseInt(cache as string) || 0, 300) : sMaxAge
|
||||
res.setHeader('Cache-Control', `public, max-age=120, s-maxage=${cacheMaxAge}, stale-while-revalidate=86400`)
|
||||
res.setHeader('Content-Type', 'image/svg+xml;charset=utf-8')
|
||||
res.statusCode = code
|
||||
res.end(badge)
|
||||
|
|
Plik diff jest za duży
Load Diff
20
package.json
20
package.json
|
@ -22,8 +22,8 @@
|
|||
]
|
||||
},
|
||||
"dependencies": {
|
||||
"@sentry/integrations": "^5.11.0",
|
||||
"@sentry/node": "^5.11.0",
|
||||
"@sentry/integrations": "^5.11.1",
|
||||
"@sentry/node": "^5.11.1",
|
||||
"badgen": "^3.0.1",
|
||||
"badgen-icons": "^0.13.0",
|
||||
"byte-size": "^6.2.0",
|
||||
|
@ -37,7 +37,7 @@
|
|||
"my-way": "^2.0.0",
|
||||
"original-url": "^1.2.3",
|
||||
"react-debounce-render": "^5.0.0",
|
||||
"semver": "^6.3.0",
|
||||
"semver": "^7.1.1",
|
||||
"serve-handler": "^6.1.2",
|
||||
"serve-marked": "^2.0.2",
|
||||
"universal-analytics": "^0.4.20",
|
||||
|
@ -49,26 +49,26 @@
|
|||
"@types/got": "^9.6.9",
|
||||
"@types/lodash.debounce": "^4.0.6",
|
||||
"@types/micro": "^7.3.3",
|
||||
"@types/node": "^12.12.24",
|
||||
"@types/node": "^12.12.25",
|
||||
"@types/react": "^16.9.17",
|
||||
"@types/react-dom": "^16.9.4",
|
||||
"@types/semver": "^6.2.0",
|
||||
"@types/supertest": "^2.0.8",
|
||||
"@types/url-parse": "^1.4.3",
|
||||
"@typescript-eslint/eslint-plugin": "^2.15.0",
|
||||
"@typescript-eslint/parser": "^2.15.0",
|
||||
"@typescript-eslint/eslint-plugin": "^2.16.0",
|
||||
"@typescript-eslint/parser": "^2.16.0",
|
||||
"@zeit/next-typescript": "^1.1.1",
|
||||
"csstype": "^2.6.8",
|
||||
"eslint": "^6.8.0",
|
||||
"eslint-plugin-react": "^7.17.0",
|
||||
"eslint-plugin-react": "^7.18.0",
|
||||
"fs-extra": "^8.1.0",
|
||||
"next": "^9.1.7",
|
||||
"next": "^9.2.0",
|
||||
"nodemon": "^2.0.2",
|
||||
"react": "^16.12.0",
|
||||
"react-dom": "^16.12.0",
|
||||
"supertest": "^4.0.2",
|
||||
"ts-node": "^8.6.1",
|
||||
"typescript": "^3.7.4"
|
||||
"ts-node": "^8.6.2",
|
||||
"typescript": "^3.7.5"
|
||||
},
|
||||
"engines": {
|
||||
"node": "12.x"
|
||||
|
|
Ładowanie…
Reference in New Issue