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

View File

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