mirror of
https://github.com/Mastermindzh/tidal-hifi.git
synced 2025-09-11 22:35:05 +02:00
added swagger docs
This commit is contained in:
@@ -1,7 +1,9 @@
|
||||
import { BrowserWindow, dialog } from "electron";
|
||||
import express from "express";
|
||||
import { settings } from "../../constants/settings";
|
||||
import swaggerjsdoc from "swagger-jsdoc";
|
||||
import swaggerUi from "swagger-ui-express";
|
||||
import { settingsStore } from "../../scripts/settings";
|
||||
import { settings } from "./../../constants/settings";
|
||||
import { addCurrentInfo } from "./features/current";
|
||||
import { addPlaybackControl } from "./features/player";
|
||||
import { addSettingsAPI } from "./features/settings/settings";
|
||||
@@ -11,9 +13,41 @@ import { addLegacyApi } from "./legacy";
|
||||
* Function to enable TIDAL Hi-Fi's express api
|
||||
*/
|
||||
export const startApi = (mainWindow: BrowserWindow) => {
|
||||
const port = settingsStore.get<string, number>(settings.apiSettings.port);
|
||||
const specs = swaggerjsdoc({
|
||||
definition: {
|
||||
openapi: "3.1.0",
|
||||
info: {
|
||||
title: "TIDAL Hi-Fi API",
|
||||
version: "5.12.0",
|
||||
description: "",
|
||||
license: {
|
||||
name: "MIT",
|
||||
url: "https://github.com/Mastermindzh/tidal-hifi/blob/master/LICENSE",
|
||||
},
|
||||
contact: {
|
||||
name: "Rick <mastermindzh> van Lieshout",
|
||||
url: "https://www.rickvanlieshout.com",
|
||||
},
|
||||
},
|
||||
servers: [
|
||||
{
|
||||
url: `http://localhost:${port}`,
|
||||
},
|
||||
],
|
||||
externalDocs: {
|
||||
description: "swagger.json",
|
||||
url: "swagger.json",
|
||||
},
|
||||
},
|
||||
apis: ["**/*.ts"],
|
||||
});
|
||||
|
||||
const expressApp = express();
|
||||
expressApp.use(express.json());
|
||||
expressApp.use("/docs", swaggerUi.serve, swaggerUi.setup(specs));
|
||||
expressApp.get("/", (req, res) => res.send("Hello World!"));
|
||||
expressApp.get("/swagger.json", (req, res) => res.json(specs));
|
||||
|
||||
// add features
|
||||
addLegacyApi(expressApp, mainWindow);
|
||||
@@ -21,7 +55,6 @@ export const startApi = (mainWindow: BrowserWindow) => {
|
||||
addCurrentInfo(expressApp);
|
||||
addSettingsAPI(expressApp, mainWindow);
|
||||
|
||||
const port = settingsStore.get<string, number>(settings.apiSettings.port);
|
||||
const expressInstance = expressApp.listen(port, "127.0.0.1");
|
||||
expressInstance.on("error", function (e: { code: string }) {
|
||||
let message = e.code;
|
||||
|
Reference in New Issue
Block a user