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 => { let name = file.replace('.js', '') // if custom add to name if (request.params.namespace === 'custom') { name += ' (custom)' } handlers.push({ 'name': file.replace('.js', ''), 'className': file, 'file': directoryPath + file }) }) }) reply .code(200) .send({ 'data': handlers }) }) }