#12: Fix static serve of manifest & robots

This commit is contained in:
Elian Doran 2024-05-12 16:14:40 +03:00
parent 80151c2b2f
commit 5d6375d845
No known key found for this signature in database
4 changed files with 25 additions and 6 deletions

View File

@ -85,6 +85,10 @@ const app = startTrilium({
getInitialTheme() {
return electron.nativeTheme.shouldUseDarkColors ? 'dark' : 'light';
}
},
registerAdditionalMiddleware(app) {
// No additional express middleware required on Electron.
},
});
electronRouting(app);

View File

@ -34,10 +34,9 @@ function buildApp(appConfig: AppConfig) {
app.use(express.urlencoded({ extended: false }));
app.use(cookieParser());
app.use(express.static(path.join(__dirname, 'public/root')));
app.use(`/manifest.webmanifest`, express.static(path.join(__dirname, 'public/manifest.webmanifest')));
app.use(`/robots.txt`, express.static(path.join(__dirname, 'public/robots.txt')));
app.use(sessionParser);
app.use(favicon(`${__dirname}/../../common/images/app-icons/win/icon.ico`));
appConfig.registerAdditionalMiddleware(app);
require('./routes/assets').register(app);
require('./routes/routes').register(app, appConfig);

View File

@ -1,4 +1,6 @@
import startTrilium = require("./www");
import path = require("path");
import express = require("express");
startTrilium({
setupCompleteCallback: (res) => {
@ -8,5 +10,11 @@ startTrilium({
getInitialTheme() {
// default based on the poll in https://github.com/zadam/trilium/issues/2516
return "dark";
}
},
registerAdditionalMiddleware(app) {
const assetsDir = path.join(__dirname, "..", "..", "client", "assets");
app.use(`/manifest.webmanifest`, express.static(path.join(assetsDir, 'manifest.webmanifest')));
app.use(`/robots.txt`, express.static(path.join(assetsDir, 'robots.txt')));
},
});

View File

@ -1,4 +1,5 @@
import { Response } from "express";
import type { Express } from "express";
export type InitialThemeCallback = () => "dark" | "light";
@ -18,6 +19,13 @@ export interface InitDbOptions {
* Handles differences between clients, for example allowing different behaviour when running from the web server versus the desktop application.
*/
export interface AppConfig extends InitDbOptions {
/**
* Called when the express app is built, in order to define additional middleware that might be specific to a web or desktop application.
*
* @param app the express app to add the middleware on.
*/
registerAdditionalMiddleware: (app: Express) => void;
/** Callback to be invoked when first setup is complete. */
setupCompleteCallback: SetupCompleteCallback;
}