// Require the framework and instantiate it import axios from 'axios'; let yealinkbaseurl = "http://10.42.0.186/cgi-bin/ConfigManApp.com" function send_request(params) { axios.get(yealinkbaseurl, { auth: { username: "admin", password: "admin" }, params: params, // Query parameters }) } // ESM import Fastify from 'fastify' const fastify = Fastify({ logger: true }) import mqtt from 'mqtt'; const client = mqtt.connect("mqtt://127.0.0.1"); client.on("connect", () => { client.subscribe("bitlair/telefoon/dial", (err) => { }); client.subscribe("bitlair/telefoon/key", (err) => { }); }); client.on('message', function (topic, message) { // message is Buffer switch (topic) { case "bitlair/telefoon/dial": console.log("Dialing "+message) send_request({"number": message, "outgoing_uri": 'URI'}) break case "bitlair/telefoon/key": console.log("Pressing "+message) send_request({"key": message}) break default: break } }) // Declare a route fastify.get('/', function (request, reply) { reply.send({ hello: 'world' }) //client.send(request.) client.publish("bitlair/telefoon/"+request.query.event, JSON.stringify(request.query)); }) // Run the server! fastify.listen({ port: 80, host: '0.0.0.0' }, function (err, address) { if (err) { fastify.log.error(err) process.exit(1) } // Server is now listening on ${address} })