From 6f28da2918086eff094107daf5701e930fdb5334 Mon Sep 17 00:00:00 2001 From: Amio Date: Sat, 4 Aug 2018 23:40:54 +0800 Subject: [PATCH] docs: add index-api.md --- libs/index-api.md | 6 ++++++ libs/serve-api.js | 6 ++++++ 2 files changed, 12 insertions(+) create mode 100644 libs/index-api.md diff --git a/libs/index-api.md b/libs/index-api.md new file mode 100644 index 0000000..790407a --- /dev/null +++ b/libs/index-api.md @@ -0,0 +1,6 @@ +# api.badgen.net + +## Examples + +- https://api.badgen.net/npm/v/micro +- https://api.badgen.net/npm/dependents/got diff --git a/libs/serve-api.js b/libs/serve-api.js index af06109..b72574a 100644 --- a/libs/serve-api.js +++ b/libs/serve-api.js @@ -1,3 +1,5 @@ +const fs = require('fs') +const path = require('path') const { send } = require('micro') const { router, get } = require('micro-fork') const liveFunctions = require('./live-fns/_index.js') @@ -15,6 +17,10 @@ const apiHandlers = Object.entries(liveFunctions).map(([name, fn]) => { }) }) +const indexContent = fs.readFileSync(path.join(__dirname, 'index-api.md'), 'utf8') +const serveIndex = (req, res) => send(res, 200, indexContent) + module.exports = router()( + get('/', serveIndex), ...apiHandlers )