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