kopia lustrzana https://github.com/badgen/badgen.net
init now v2 for static badges
rodzic
8b44e373e7
commit
040f160fe2
|
@ -1,4 +1,5 @@
|
|||
node_modules
|
||||
yarn.lock
|
||||
public
|
||||
dist
|
||||
.next
|
||||
|
|
|
@ -0,0 +1,47 @@
|
|||
const url = require('url')
|
||||
const qs = require('querystring')
|
||||
const badgen = require('badgen')
|
||||
const { send } = require('micro')
|
||||
|
||||
const CACHE_CONTROL = `public, max-age=60, stale-while-revalidate=604800, stale-if-error=604800`
|
||||
const noneSquareIconWidths = {
|
||||
awesome: 20,
|
||||
codeclimate: 18,
|
||||
lgtm: 19
|
||||
}
|
||||
|
||||
// parse url to params & query
|
||||
const parseURL = (req) => {
|
||||
const { pathname, query = {} } = url.parse(req.url, true)
|
||||
const [,, subject = '', status = '', color] = pathname.split('/')
|
||||
return {
|
||||
query,
|
||||
params: {
|
||||
subject: qs.unescape(subject),
|
||||
status: qs.unescape(status),
|
||||
color
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = (req, res, options = {}) => {
|
||||
const { code = 200, sMaxAge = '604800' } = options
|
||||
const { params, query } = parseURL(req)
|
||||
|
||||
const hostStyle = req.headers.host === 'flat.badgen.net' ? 'flat' : undefined
|
||||
const { subject, status, color } = options.params || params
|
||||
const { style, label, list, icon, iconWidth, color: queryColor } = query
|
||||
|
||||
const badge = badgen({
|
||||
subject: typeof label !== 'undefined' ? label : subject,
|
||||
status: String(list ? status.replace(/,/g, ' | ') : status),
|
||||
color: queryColor || color,
|
||||
style: style || hostStyle,
|
||||
icon,
|
||||
iconWidth: iconWidth || noneSquareIconWidths[icon]
|
||||
})
|
||||
|
||||
res.setHeader('Content-Type', 'image/svg+xml;charset=utf-8')
|
||||
res.setHeader('Cache-Control', `${CACHE_CONTROL}, s-maxage=${sMaxAge}`)
|
||||
send(res, code, badge)
|
||||
}
|
|
@ -0,0 +1,5 @@
|
|||
const { send } = require('micro')
|
||||
|
||||
module.exports = (req, res) => {
|
||||
send(res, 200, 111)
|
||||
}
|
33
now.json
33
now.json
|
@ -1,28 +1,11 @@
|
|||
{
|
||||
"alias": [
|
||||
"api.badgen.net",
|
||||
"flat.badgen.net",
|
||||
"badgen.net",
|
||||
"badgen"
|
||||
"version": 2,
|
||||
"builds": [
|
||||
{ "src": "package.json", "use": "@now/static-build" },
|
||||
{ "src": "endpoints/*.js", "use": "@now/node" }
|
||||
],
|
||||
"files": [
|
||||
"package-lock.json",
|
||||
"next.config.js",
|
||||
"service.js",
|
||||
"libs",
|
||||
"pages",
|
||||
"static",
|
||||
"components"
|
||||
],
|
||||
"env": {
|
||||
"GH_TOKEN": "@badgen-gh-token",
|
||||
"SENTRY_URI": "@badgen-sentry-uri",
|
||||
"TRACKING_GA": "@badgen-tracking-ga"
|
||||
},
|
||||
"engines": {
|
||||
"node": "^10.0.0"
|
||||
},
|
||||
"github": {
|
||||
"autoAlias": false
|
||||
}
|
||||
"routes": [
|
||||
{ "src": "^/static/(.*)", "dest": "/static/$1" },
|
||||
{ "src": "^/badge/.*", "dest": "/endpoints/badge.js" }
|
||||
]
|
||||
}
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
"lint": "standard",
|
||||
"dev": "micro-dev service.js -s -i .next",
|
||||
"dev:web": "next",
|
||||
"build": "NODE_ENV=production next build && next export -o public",
|
||||
"now-build": "NODE_ENV=production next build && next export -o dist",
|
||||
"pretest": "npm run lint",
|
||||
"test": "tap test/*.js --reporter spec -j12",
|
||||
"start": "node service.js",
|
||||
|
|
Ładowanie…
Reference in New Issue