Fixed favicon not found etc.

This commit is contained in:
SamTV12345 2024-08-20 19:36:03 +02:00
parent 8ab47761df
commit 33d80cdbad
3 changed files with 11 additions and 9 deletions

View file

@ -7,12 +7,11 @@ const padManager = require('../../db/PadManager');
exports.expressCreateServer = (hookName:string, args:ArgsExpressType, cb:Function) => {
// redirects browser to the pad's sanitized url if needed. otherwise, renders the html
args.app.use(async (req, res, next) => {
console.log("Hier gehe ich durch")
const possiblePad = req.params.pad
const possiblePad = decodeURIComponent(req.params.pad)
try {
if (!possiblePad) {
next()
return next()
}
// ensure the padname is valid and the url doesn't end with a /
if (!padManager.isValidPadId(possiblePad) || /\/$/.test(req.url)) {
@ -24,13 +23,14 @@ exports.expressCreateServer = (hookName:string, args:ArgsExpressType, cb:Functio
if (sanitizedPadId === possiblePad) {
// the pad id was fine, so just render it
next();
return next();
} else {
// the pad id was sanitized, so we redirect to the sanitized version
const realURL =
encodeURIComponent(sanitizedPadId) + new URL(req.url, 'http://invalid.invalid').search;
res.header('Location', realURL);
res.status(302).send(`You should be redirected to <a href="${realURL}">${realURL}</a>`);
return
}
}
catch (e) {

View file

@ -6,6 +6,7 @@ import {PartType} from "../../types/PartType";
const fs = require('fs').promises;
import {minify} from '../../utils/Minify';
import path from 'node:path';
import {ArgsExpressType} from "../../types/ArgsExpressType";
const plugins = require('../../../static/js/pluginfw/plugin_defs');
const settings = require('../../utils/Settings');
@ -30,7 +31,7 @@ const getTar = async () => {
return tar;
};
exports.expressPreSession = async (hookName:string, {app}:any) => {
exports.expressPreSession = async (hookName:string, {app}:ArgsExpressType) => {
// Minify will serve static files compressed (minify enabled). It also has
// file-specific hacks for ace/require-kernel/etc.
@ -39,7 +40,7 @@ exports.expressPreSession = async (hookName:string, {app}:any) => {
// serve plugin definitions
// not very static, but served here so that client can do
// require("pluginfw/static/js/plugin-definitions.js");
app.get('/pluginfw/plugin-definitions.json', (req: any, res:any, next:Function) => {
app.get('/pluginfw/plugin-definitions.json', (req, res, next) => {
const clientParts = plugins.parts.filter((part: PartType) => part.client_hooks != null);
const clientPlugins:MapArrayType<string> = {};
for (const name of new Set(clientParts.map((part: PartType) => part.plugin))) {
@ -50,7 +51,6 @@ exports.expressPreSession = async (hookName:string, {app}:any) => {
}
res.setHeader('Content-Type', 'application/json; charset=utf-8');
res.setHeader('Cache-Control', `public, max-age=${settings.maxAge}`);
res.write(JSON.stringify({plugins: clientPlugins, parts: clientParts}));
res.end();
res.json({plugins: clientPlugins, parts: clientParts});
});
};

View file

@ -72,7 +72,9 @@ const checkAccess = async (req:any, res:any, next: Function) => {
(r) => (skip || (r != null && r.filter((x) => (!requireAdmin || !x)).length > 0))) as boolean[];
} catch (err:any) {
httpLogger.error(`Error in preAuthorize hook: ${err.stack || err.toString()}`);
if (!skip) res.status(500).send('Internal Server Error');
if (!skip) {
res.status(500).send('Internal Server Error');
}
return;
}
if (skip) return;