2018-06-26 05:39:49 +00:00
|
|
|
const http = require('http')
|
|
|
|
const router = require('find-my-way')()
|
2018-07-03 15:22:38 +00:00
|
|
|
const setupLiveBadge = require('./libs/setup-live-badge.js')
|
2018-07-10 12:37:48 +00:00
|
|
|
const setupRedirectBadge = require('./libs/setup-redirect-badge.js')
|
2018-07-03 15:22:38 +00:00
|
|
|
const serveIndex = require('./libs/serve-index.js')
|
2018-07-12 06:47:40 +00:00
|
|
|
const serve404 = require('./libs/serve-404.js')
|
2018-07-12 06:31:48 +00:00
|
|
|
const { serveBadge, serveListBadge } = require('./libs/serve-badge.js')
|
|
|
|
|
|
|
|
router.get('/badge/:subject/:status', serveBadge)
|
|
|
|
router.get('/badge/:subject/:status/:color', serveBadge)
|
|
|
|
router.get('/list/:subject/:status', serveListBadge)
|
|
|
|
router.get('/list/:subject/:status/:color', serveListBadge)
|
2018-06-26 05:39:49 +00:00
|
|
|
|
2018-07-03 15:22:38 +00:00
|
|
|
setupLiveBadge(router)
|
2018-07-10 12:37:48 +00:00
|
|
|
setupRedirectBadge(router)
|
2018-06-26 05:39:49 +00:00
|
|
|
|
2018-06-28 09:34:42 +00:00
|
|
|
router.get('/', serveIndex)
|
2018-07-12 06:47:40 +00:00
|
|
|
router.all('/*', serve404)
|
2018-06-26 05:39:49 +00:00
|
|
|
|
2018-07-03 15:22:38 +00:00
|
|
|
const rootHandler = (req, res) => {
|
2018-06-26 15:38:40 +00:00
|
|
|
try {
|
|
|
|
router.lookup(req, res)
|
|
|
|
} catch (ex) {
|
|
|
|
console.error(ex)
|
|
|
|
res.statusCode = 500
|
|
|
|
res.end()
|
|
|
|
}
|
2018-07-03 15:22:38 +00:00
|
|
|
}
|
2018-06-29 16:52:17 +00:00
|
|
|
|
|
|
|
const server = http.createServer(rootHandler)
|
2018-06-26 05:39:49 +00:00
|
|
|
server.listen(3000)
|