kopia lustrzana https://github.com/badgen/badgen.net
chore: limit CDN cache to 5 mins (#335)
* fix: missing cheerio * chore: set cdn cache to 5 min * chore: eslint --fix * chore: add github action configpull/336/head
rodzic
b9da463bc2
commit
bfa4d1bb16
|
@ -0,0 +1,26 @@
|
||||||
|
name: Node CI
|
||||||
|
|
||||||
|
on: [push]
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build:
|
||||||
|
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
|
strategy:
|
||||||
|
matrix:
|
||||||
|
node-version: [10.x, 12.x]
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v1
|
||||||
|
- name: Use Node.js ${{ matrix.node-version }}
|
||||||
|
uses: actions/setup-node@v1
|
||||||
|
with:
|
||||||
|
node-version: ${{ matrix.node-version }}
|
||||||
|
- name: npm install, build, and test
|
||||||
|
run: |
|
||||||
|
npm ci
|
||||||
|
npm run lint
|
||||||
|
npm run build --if-present
|
||||||
|
env:
|
||||||
|
CI: true
|
|
@ -1,4 +1,5 @@
|
||||||
import got from '../libs/got'
|
import got from '../libs/got'
|
||||||
|
import cheerio from 'cheerio'
|
||||||
import { createBadgenHandler, PathArgs } from '../libs/create-badgen-handler'
|
import { createBadgenHandler, PathArgs } from '../libs/create-badgen-handler'
|
||||||
|
|
||||||
export default createBadgenHandler({
|
export default createBadgenHandler({
|
||||||
|
|
|
@ -16,13 +16,13 @@ export default createBadgenHandler({
|
||||||
|
|
||||||
async function handler ({ topic, path }: PathArgs) {
|
async function handler ({ topic, path }: PathArgs) {
|
||||||
if (path.startsWith('http/')) {
|
if (path.startsWith('http/')) {
|
||||||
path = path.slice(0, 4) + ':/' + path.slice(4);
|
path = path.slice(0, 4) + ':/' + path.slice(4)
|
||||||
} else if (path.startsWith('https/')) {
|
} else if (path.startsWith('https/')) {
|
||||||
path = path.slice(0, 5) + ':/' + path.slice(5);
|
path = path.slice(0, 5) + ':/' + path.slice(5)
|
||||||
} else if (path.startsWith('http:/')) {
|
} else if (path.startsWith('http:/')) {
|
||||||
path = path.slice(0, 5) + '/' + path.slice(5);
|
path = path.slice(0, 5) + '/' + path.slice(5)
|
||||||
} else if (path.startsWith('https:/')) {
|
} else if (path.startsWith('https:/')) {
|
||||||
path = path.slice(0, 6) + '/' + path.slice(6);
|
path = path.slice(0, 6) + '/' + path.slice(6)
|
||||||
}
|
}
|
||||||
const endpoint = `https://img.badgesize.io/${path}.json`
|
const endpoint = `https://img.badgesize.io/${path}.json`
|
||||||
const { prettySize, color } = await got(endpoint, {
|
const { prettySize, color } = await got(endpoint, {
|
||||||
|
|
|
@ -13,7 +13,7 @@ type ServeBadgeOptions = {
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function (req: IncomingMessage, res: ServerResponse, options: ServeBadgeOptions) {
|
export default function (req: IncomingMessage, res: ServerResponse, options: ServeBadgeOptions) {
|
||||||
const { code = 200, sMaxAge = 10800, query = {}, params } = options
|
const { code = 200, sMaxAge = 300, query = {}, params } = options
|
||||||
|
|
||||||
const { subject, status, color } = params
|
const { subject, status, color } = params
|
||||||
const { label, labelColor, icon, iconWidth, list, scale } = query
|
const { label, labelColor, icon, iconWidth, list, scale } = query
|
||||||
|
@ -33,8 +33,7 @@ export default function (req: IncomingMessage, res: ServerResponse, options: Ser
|
||||||
scale: parseFloat(scale || '1'),
|
scale: parseFloat(scale || '1'),
|
||||||
})
|
})
|
||||||
|
|
||||||
const staleControl = `stale-while-revalidate=604800, stale-if-error=604800`
|
const cacheControl = `public, max-age=120, s-maxage=${sMaxAge}, stale-while-revalidate=86400`
|
||||||
const cacheControl = `public, max-age=60, s-maxage=${sMaxAge}, ${staleControl}`
|
|
||||||
res.setHeader('Cache-Control', cacheControl)
|
res.setHeader('Cache-Control', cacheControl)
|
||||||
res.setHeader('Content-Type', 'image/svg+xml;charset=utf-8')
|
res.setHeader('Content-Type', 'image/svg+xml;charset=utf-8')
|
||||||
res.statusCode = code
|
res.statusCode = code
|
||||||
|
|
Ładowanie…
Reference in New Issue