import * as fs from 'fs' import * as path from 'path' /** * getting handlers * * @author Björn Hase, me@herr-hase.wtf * @license http://opensource.org/licenses/MIT The MIT License * @link https://gitea.node001.net/HerrHase/super-hog * */ export default async function(fastify, opts) { fastify.get('/handler/:namespace(request|action)', async function (request, reply) { // handlers that found const handlers = [] // directories to find const directories = [ 'custom', 'handlers' ] // getting directories.forEach((directory) => { // create path const directoryPath = './../runner/' + directory + '/' + request.params.namespace // adding each from directory fs.readdirSync(directoryPath).forEach(file => { handlers.push({ 'name': file.replace('.js', ''), 'file': path.resolve(file) }) }) }) reply .code(200) .send({ 'data': handlers }) }) }