UNPKG

777 BPlain TextView Raw
1import dotProp from 'dot-prop'
2import { Server } from '../types/fastify'
3
4export default async (app: Server) => {
5 app.get('/', (request, reply) => {
6 reply.send(config.config)
7 })
8
9 app.get('/:path', async (request, reply) => {
10 const value = dotProp.get(config.config, request.params.path)
11 if (value == null) return reply.sendError(404, `Config property ${request.params.path} does not exist!`)
12 reply.send(value)
13 })
14
15 app.post('/:path', async (request, reply) => {
16 await config.set(request.params.path, request.body)
17 reply.send(typeof request.body === 'string' ? JSON.stringify(request.body) : request.body)
18 })
19
20 app.delete('/:path', async (request, reply) => {
21 await config.set(request.params.path, null)
22 reply.code(200).send()
23 })
24}