mirror of
https://github.com/zadam/trilium.git
synced 2025-11-02 03:16:11 +01:00
fix(docs): unpack the OpenAPI spec files, and have Swagger UI read from the unpacked files
This commit is contained in:
@@ -37,7 +37,9 @@ const config: ForgeConfig = {
|
|||||||
executableName: EXECUTABLE_NAME,
|
executableName: EXECUTABLE_NAME,
|
||||||
name: PRODUCT_NAME,
|
name: PRODUCT_NAME,
|
||||||
overwrite: true,
|
overwrite: true,
|
||||||
asar: true,
|
asar: {
|
||||||
|
unpack: "{**/node_modules/swagger-ui-dist/**,**/assets/*.yaml,**/assets/*.json}"
|
||||||
|
},
|
||||||
icon: path.join(APP_ICON_PATH, "icon"),
|
icon: path.join(APP_ICON_PATH, "icon"),
|
||||||
...macosSignConfiguration,
|
...macosSignConfiguration,
|
||||||
windowsSign: windowsSignConfiguration,
|
windowsSign: windowsSignConfiguration,
|
||||||
|
|||||||
@@ -3,12 +3,22 @@ import swaggerUi from "swagger-ui-express";
|
|||||||
import { join } from "path";
|
import { join } from "path";
|
||||||
import yaml from "js-yaml";
|
import yaml from "js-yaml";
|
||||||
import type { JsonObject } from "swagger-ui-express";
|
import type { JsonObject } from "swagger-ui-express";
|
||||||
import { readFileSync } from "fs";
|
import { readFileSync, existsSync } from "fs";
|
||||||
import { RESOURCE_DIR } from "../services/resource_dir";
|
import { RESOURCE_DIR } from "../services/resource_dir";
|
||||||
|
|
||||||
export default function register(app: Application) {
|
export default function register(app: Application) {
|
||||||
const etapiDocument = yaml.load(readFileSync(join(RESOURCE_DIR, "etapi.openapi.yaml"), "utf8")) as JsonObject;
|
// In packaged Electron apps, check if we need to read from the unpacked directory
|
||||||
const apiDocument = JSON.parse(readFileSync(join(RESOURCE_DIR, "openapi.json"), "utf-8"));
|
let resourceDir = RESOURCE_DIR;
|
||||||
|
if (resourceDir.includes('app.asar')) {
|
||||||
|
const unpackedDir = RESOURCE_DIR.replace('app.asar', 'app.asar.unpacked');
|
||||||
|
// Check if the unpacked directory has our files
|
||||||
|
if (existsSync(join(unpackedDir, "etapi.openapi.yaml"))) {
|
||||||
|
resourceDir = unpackedDir;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const etapiDocument = yaml.load(readFileSync(join(resourceDir, "etapi.openapi.yaml"), "utf8")) as JsonObject;
|
||||||
|
const apiDocument = JSON.parse(readFileSync(join(resourceDir, "openapi.json"), "utf-8"));
|
||||||
|
|
||||||
app.use(
|
app.use(
|
||||||
"/etapi/docs/",
|
"/etapi/docs/",
|
||||||
|
|||||||
Reference in New Issue
Block a user