change for api route

This commit is contained in:
Darius
2025-11-18 22:08:00 +01:00
parent 22f8e28ed3
commit 4b31edd310
2 changed files with 105 additions and 100 deletions

View File

@@ -37,8 +37,10 @@ const haService = new HomeAssistantService(haClient);
const tidalClient = new TidalClient(server.axios.tidal); const tidalClient = new TidalClient(server.axios.tidal);
const tidalService = new TidalService(tidalClient); const tidalService = new TidalService(tidalClient);
server.register(
async (fastify) => {
// HOME ASSISTANT // HOME ASSISTANT
server.get("/homeassistant/desk/position", async (_request, reply) => { fastify.get("/homeassistant/desk/position", async (_request, reply) => {
const result = await haService.getDeskPosition(); const result = await haService.getDeskPosition();
if (!result) { if (!result) {
@@ -53,7 +55,7 @@ server.get("/homeassistant/desk/position", async (_request, reply) => {
}; };
}); });
server.post( fastify.post(
"/homeassistant/desk/stand", "/homeassistant/desk/stand",
{ preHandler: verifyAPIKey }, { preHandler: verifyAPIKey },
async (_request, reply) => { async (_request, reply) => {
@@ -68,7 +70,7 @@ server.post(
}, },
); );
server.get("/homeassistant/temperature", async (_request, reply) => { fastify.get("/homeassistant/temperature", async (_request, reply) => {
const result = await haService.getTemperatureText(); const result = await haService.getTemperatureText();
if (!result) { if (!result) {
@@ -82,7 +84,7 @@ server.get("/homeassistant/temperature", async (_request, reply) => {
}); });
// TIDAL // TIDAL
server.get("/tidal/song", async (_request, reply) => { fastify.get("/tidal/song", async (_request, reply) => {
const result = await tidalService.getSong(); const result = await tidalService.getSong();
if (!result) { if (!result) {
@@ -93,7 +95,7 @@ server.get("/tidal/song", async (_request, reply) => {
return { result }; return { result };
}); });
server.get("/tidal/songFormatted", async (_request, reply) => { fastify.get("/tidal/songFormatted", async (_request, reply) => {
const result = await tidalService.getSongFormatted(); const result = await tidalService.getSongFormatted();
if (!result) { if (!result) {
@@ -104,7 +106,7 @@ server.get("/tidal/songFormatted", async (_request, reply) => {
return { result }; return { result };
}); });
server.get("/tidal/volume", async (_request, reply) => { fastify.get("/tidal/volume", async (_request, reply) => {
const result = await tidalService.getVolume(); const result = await tidalService.getVolume();
if (!result) { if (!result) {
@@ -115,7 +117,7 @@ server.get("/tidal/volume", async (_request, reply) => {
return { result }; return { result };
}); });
server.post( fastify.post(
"/tidal/volume", "/tidal/volume",
{ preHandler: verifyAPIKey }, { preHandler: verifyAPIKey },
async (request, reply) => { async (request, reply) => {
@@ -132,9 +134,12 @@ server.post(
); );
// Default // Default
server.get("/ping", async (_request, _reply) => { fastify.get("/ping", async (_request, _reply) => {
return "pong\n"; return "pong\n";
}); });
},
{ prefix: "/api" },
);
server.listen({ port: 8080 }, (err, address) => { server.listen({ port: 8080 }, (err, address) => {
if (err) { if (err) {

View File

@@ -1,48 +1,48 @@
### Simple GET Request ### Simple GET Request
GET http://localhost:8080/ping GET http://localhost:8080/api/ping
### ###
#################### HA ####################### #################### HA #######################
### Simple GET Desk Position ### Simple GET Desk Position
GET http://localhost:8080/homeassistant/desk/position GET http://localhost:8080/api/homeassistant/desk/position
### ###
### Simple GET Stand Automation ### Simple GET Stand Automation
GET http://localhost:8080/homeassistant/desk/stand GET http://localhost:8080/api/homeassistant/desk/stand
### ###
### Simple POST Stand Automation ### Simple POST Stand Automation
POST http://localhost:8080/homeassistant/desk/stand POST http://localhost:8080/api/homeassistant/desk/stand
### ###
### Simple GET Temps ### Simple GET Temps
GET http://localhost:8080/homeassistant/temperature GET http://localhost:8080/api/homeassistant/temperature
### ###
#################### TIDAL ####################### #################### TIDAL #######################
### Simple GET Song ### Simple GET Song
GET http://localhost:8080/tidal/song GET http://localhost:8080/api/tidal/song
### ###
### Simple GET Song Formatted ### Simple GET Song Formatted
GET http://localhost:8080/tidal/songFormatted GET http://localhost:8080/api/tidal/songFormatted
### ###
### Simple GET Volume ### Simple GET Volume
GET http://localhost:8080/tidal/volume GET http://localhost:8080/api/tidal/volume
### ###
### Simple SET Volume ### Simple SET Volume
POST http://localhost:8080/tidal/volume POST http://localhost:8080/api/tidal/volume
### ###