You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

47 lines
1.1 KiB

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
})
})
}