mirror of
https://github.com/TriliumNext/Notes.git
synced 2025-07-27 18:12:29 +08:00
chore(monorepo/server): remove top-level await completely
This commit is contained in:
parent
6e35806340
commit
6543d6c362
@ -2,7 +2,6 @@
|
|||||||
"name": "@triliumnext/server",
|
"name": "@triliumnext/server",
|
||||||
"version": "0.0.1",
|
"version": "0.0.1",
|
||||||
"private": true,
|
"private": true,
|
||||||
"type": "module",
|
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"express": "4.21.2",
|
"express": "4.21.2",
|
||||||
"express-openid-connect": "^2.17.1",
|
"express-openid-connect": "^2.17.1",
|
||||||
|
@ -20,10 +20,10 @@ import openID from "./services/open_id.js";
|
|||||||
import { t } from "i18next";
|
import { t } from "i18next";
|
||||||
import eventService from "./services/events.js";
|
import eventService from "./services/events.js";
|
||||||
import log from "./services/log.js";
|
import log from "./services/log.js";
|
||||||
|
import "./services/handlers.js";
|
||||||
|
import "./becca/becca_loader.js";
|
||||||
|
|
||||||
await import("./services/handlers.js");
|
export default async function buildApp() {
|
||||||
await import("./becca/becca_loader.js");
|
|
||||||
|
|
||||||
const app = express();
|
const app = express();
|
||||||
|
|
||||||
const scriptDir = dirname(fileURLToPath(import.meta.url));
|
const scriptDir = dirname(fileURLToPath(import.meta.url));
|
||||||
@ -136,4 +136,5 @@ if (utils.isElectron) {
|
|||||||
(await import("@electron/remote/main/index.js")).initialize();
|
(await import("@electron/remote/main/index.js")).initialize();
|
||||||
}
|
}
|
||||||
|
|
||||||
export default app;
|
return app;
|
||||||
|
}
|
||||||
|
@ -6,8 +6,8 @@
|
|||||||
import { initializeTranslations } from "./services/i18n.js";
|
import { initializeTranslations } from "./services/i18n.js";
|
||||||
|
|
||||||
async function startApplication() {
|
async function startApplication() {
|
||||||
|
await initializeTranslations();
|
||||||
await import("./www.js");
|
await import("./www.js");
|
||||||
}
|
}
|
||||||
|
|
||||||
await initializeTranslations();
|
startApplication();
|
||||||
await startApplication();
|
|
||||||
|
@ -1,16 +1,17 @@
|
|||||||
import type { Application } from "express";
|
import type { Application } from "express";
|
||||||
import swaggerUi from "swagger-ui-express";
|
import swaggerUi from "swagger-ui-express";
|
||||||
import { readFile } from "fs/promises";
|
|
||||||
import { fileURLToPath } from "url";
|
import { fileURLToPath } from "url";
|
||||||
import { dirname, join } from "path";
|
import { dirname, 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";
|
||||||
|
|
||||||
const __dirname = dirname(fileURLToPath(import.meta.url));
|
const __dirname = dirname(fileURLToPath(import.meta.url));
|
||||||
const etapiDocument = yaml.load(await readFile(join(__dirname, "../etapi/etapi.openapi.yaml"), "utf8")) as JsonObject;
|
|
||||||
const apiDocument = JSON.parse(await readFile(join(__dirname, "api", "openapi.json"), "utf-8"));
|
|
||||||
|
|
||||||
function register(app: Application) {
|
export default function register(app: Application) {
|
||||||
|
const etapiDocument = yaml.load(readFileSync(join(__dirname, "../etapi/etapi.openapi.yaml"), "utf8")) as JsonObject;
|
||||||
|
const apiDocument = JSON.parse(readFileSync(join(__dirname, "api", "openapi.json"), "utf-8"));
|
||||||
|
|
||||||
app.use(
|
app.use(
|
||||||
"/etapi/docs/",
|
"/etapi/docs/",
|
||||||
swaggerUi.serveFiles(etapiDocument),
|
swaggerUi.serveFiles(etapiDocument),
|
||||||
@ -29,7 +30,3 @@ function register(app: Application) {
|
|||||||
})
|
})
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export default {
|
|
||||||
register
|
|
||||||
};
|
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
import { ipcMain } from "electron";
|
import { ipcMain } from "electron";
|
||||||
import type { Application } from "express";
|
|
||||||
|
|
||||||
interface Response {
|
interface Response {
|
||||||
statusCode: number;
|
statusCode: number;
|
||||||
@ -10,7 +9,7 @@ interface Response {
|
|||||||
send: (obj: {}) => void; // eslint-disable-line @typescript-eslint/no-empty-object-type
|
send: (obj: {}) => void; // eslint-disable-line @typescript-eslint/no-empty-object-type
|
||||||
}
|
}
|
||||||
|
|
||||||
function init(app: Application) {
|
function init(app: Express.Application) {
|
||||||
ipcMain.on("server-request", (event, arg) => {
|
ipcMain.on("server-request", (event, arg) => {
|
||||||
const req = {
|
const req = {
|
||||||
url: arg.url,
|
url: arg.url,
|
||||||
|
@ -12,19 +12,6 @@ import AbstractBeccaEntity from "../becca/entities/abstract_becca_entity.js";
|
|||||||
import type { IncomingMessage, Server as HttpServer } from "http";
|
import type { IncomingMessage, Server as HttpServer } from "http";
|
||||||
import type { EntityChange } from "./entity_changes_interface.js";
|
import type { EntityChange } from "./entity_changes_interface.js";
|
||||||
|
|
||||||
if (isDev) {
|
|
||||||
const chokidar = (await import("chokidar")).default;
|
|
||||||
const debounce = (await import("debounce")).default;
|
|
||||||
const debouncedReloadFrontend = debounce(() => reloadFrontend("source code change"), 200);
|
|
||||||
chokidar
|
|
||||||
.watch("src/public", {
|
|
||||||
ignored: "src/public/app/doc_notes/en/User Guide"
|
|
||||||
})
|
|
||||||
.on("add", debouncedReloadFrontend)
|
|
||||||
.on("change", debouncedReloadFrontend)
|
|
||||||
.on("unlink", debouncedReloadFrontend);
|
|
||||||
}
|
|
||||||
|
|
||||||
let webSocketServer!: WebSocketServer;
|
let webSocketServer!: WebSocketServer;
|
||||||
let lastSyncedPush: number | null = null;
|
let lastSyncedPush: number | null = null;
|
||||||
|
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
#!/usr/bin/env node
|
#!/usr/bin/env node
|
||||||
|
|
||||||
import app from "./app.js";
|
|
||||||
import sessionParser from "./routes/session_parser.js";
|
import sessionParser from "./routes/session_parser.js";
|
||||||
import fs from "fs";
|
import fs from "fs";
|
||||||
import http from "http";
|
import http from "http";
|
||||||
@ -13,6 +12,8 @@ import ws from "./services/ws.js";
|
|||||||
import utils from "./services/utils.js";
|
import utils from "./services/utils.js";
|
||||||
import port from "./services/port.js";
|
import port from "./services/port.js";
|
||||||
import host from "./services/host.js";
|
import host from "./services/host.js";
|
||||||
|
import buildApp from "./app.js";
|
||||||
|
import type { Express } from "express";
|
||||||
|
|
||||||
const MINIMUM_NODE_VERSION = "20.0.0";
|
const MINIMUM_NODE_VERSION = "20.0.0";
|
||||||
|
|
||||||
@ -47,6 +48,8 @@ tmp.setGracefulCleanup();
|
|||||||
startTrilium();
|
startTrilium();
|
||||||
|
|
||||||
async function startTrilium() {
|
async function startTrilium() {
|
||||||
|
const app = await buildApp();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The intended behavior is to detect when a second instance is running, in that case open the old instance
|
* The intended behavior is to detect when a second instance is running, in that case open the old instance
|
||||||
* instead of the new one. This is complicated by the fact that it is possible to run multiple instances of Trilium
|
* instead of the new one. This is complicated by the fact that it is possible to run multiple instances of Trilium
|
||||||
@ -74,7 +77,7 @@ async function startTrilium() {
|
|||||||
log.info(`CPU model: ${cpuModel}, logical cores: ${cpuInfos.length}, freq: ${cpuInfos[0].speed} Mhz`);
|
log.info(`CPU model: ${cpuModel}, logical cores: ${cpuInfos.length}, freq: ${cpuInfos[0].speed} Mhz`);
|
||||||
}
|
}
|
||||||
|
|
||||||
const httpServer = startHttpServer();
|
const httpServer = startHttpServer(app);
|
||||||
|
|
||||||
ws.init(httpServer, sessionParser as any); // TODO: Not sure why session parser is incompatible.
|
ws.init(httpServer, sessionParser as any); // TODO: Not sure why session parser is incompatible.
|
||||||
|
|
||||||
@ -84,7 +87,7 @@ async function startTrilium() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function startHttpServer() {
|
function startHttpServer(app: Express) {
|
||||||
app.set("port", port);
|
app.set("port", port);
|
||||||
app.set("host", host);
|
app.set("host", host);
|
||||||
|
|
||||||
|
@ -1,9 +1,8 @@
|
|||||||
{
|
{
|
||||||
"extends": "../../tsconfig.base.json",
|
"extends": "../../tsconfig.base.json",
|
||||||
"compilerOptions": {
|
"compilerOptions": {
|
||||||
"module": "ESNext",
|
"module": "NodeNext",
|
||||||
"target": "ESNext",
|
"moduleResolution": "nodenext",
|
||||||
"moduleResolution": "bundler",
|
|
||||||
"outDir": "dist",
|
"outDir": "dist",
|
||||||
"types": [
|
"types": [
|
||||||
"node",
|
"node",
|
||||||
|
@ -3,8 +3,7 @@ const { join } = require('path');
|
|||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
output: {
|
output: {
|
||||||
path: join(__dirname, 'dist'),
|
path: join(__dirname, 'dist')
|
||||||
libraryTarget: "module"
|
|
||||||
},
|
},
|
||||||
plugins: [
|
plugins: [
|
||||||
new NxAppWebpackPlugin({
|
new NxAppWebpackPlugin({
|
||||||
@ -17,8 +16,5 @@ module.exports = {
|
|||||||
outputHashing: 'none',
|
outputHashing: 'none',
|
||||||
generatePackageJson: true,
|
generatePackageJson: true,
|
||||||
})
|
})
|
||||||
],
|
]
|
||||||
experiments: {
|
|
||||||
outputModule: true
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user