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.

49 lines
1.2 KiB

const schemas = require('../schemas/state.js')
const bearerAuthPlugin = require('fastify-bearer-auth')
/**
*
*
* @author Björn Hase, Tentakelfabrik
* @license http://opensource.org/licenses/MIT The MIT License
* @link https://github.com/tentakelfabrik/fastify-lowdb-riotjs-lessons-learned
*
*/
module.exports = async function (fastify, opts) {
fastify.register(bearerAuthPlugin, process.env.TOKEN.split(','))
/**
* getting current status of switch
*
*
* @param {object} request
* @param {object} reply
* @return {object}
*/
fastify.get('/state', function(request, reply) {
reply
.code(200)
.header('Content-Type', 'application/json; charset=utf-8')
.send({
'power': power
})
})
/**
* turn on
*
* @param {object} request
* @param {object} reply
* @return {object}
*/
fastify.put('/state', schemas.putSchema, function(request, reply) {
reply
.code(200)
.header('Content-Type', 'application/json; charset=utf-8')
.send({
'power': power
})
})
}