You've already forked joplin
mirror of
https://github.com/laurent22/joplin.git
synced 2025-11-23 22:36:32 +02:00
Server: Improve error when attempting to load certain routes that do not exist (#13683)
This commit is contained in:
@@ -8,6 +8,7 @@ import { AppContext, RouteType } from '../utils/types';
|
|||||||
import { localFileFromUrl } from '../utils/joplinUtils';
|
import { localFileFromUrl } from '../utils/joplinUtils';
|
||||||
import { homeUrl, loginUrl } from '../utils/urlUtils';
|
import { homeUrl, loginUrl } from '../utils/urlUtils';
|
||||||
import * as mime from '@joplin/lib/mime-utils';
|
import * as mime from '@joplin/lib/mime-utils';
|
||||||
|
import { hasOwnProperty } from '@joplin/utils/object';
|
||||||
|
|
||||||
const publicDir = `${dirname(dirname(__dirname))}/public`;
|
const publicDir = `${dirname(dirname(__dirname))}/public`;
|
||||||
|
|
||||||
@@ -33,7 +34,7 @@ async function findLocalFile(path: string): Promise<string> {
|
|||||||
const appFilePath = await localFileFromUrl(path);
|
const appFilePath = await localFileFromUrl(path);
|
||||||
if (appFilePath) return appFilePath;
|
if (appFilePath) return appFilePath;
|
||||||
|
|
||||||
if (path in pathToFileMap) return pathToFileMap[path];
|
if (hasOwnProperty(pathToFileMap, path)) return pathToFileMap[path];
|
||||||
// For now a bit of a hack to load FontAwesome fonts.
|
// For now a bit of a hack to load FontAwesome fonts.
|
||||||
if (path.indexOf('css/fontawesome/webfonts/fa-') === 0) return `node_modules/@fortawesome/fontawesome-free/${path.substr(16)}`;
|
if (path.indexOf('css/fontawesome/webfonts/fa-') === 0) return `node_modules/@fortawesome/fontawesome-free/${path.substr(16)}`;
|
||||||
|
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import { URL } from 'url';
|
|||||||
import { csrfCheck } from './csrf';
|
import { csrfCheck } from './csrf';
|
||||||
import { contextSessionId } from './requestUtils';
|
import { contextSessionId } from './requestUtils';
|
||||||
import { stripOffQueryParameters } from './urlUtils';
|
import { stripOffQueryParameters } from './urlUtils';
|
||||||
|
import { hasOwnProperty } from '@joplin/utils/object';
|
||||||
|
|
||||||
const { ltrimSlashes, rtrimSlashes } = require('@joplin/lib/path-utils');
|
const { ltrimSlashes, rtrimSlashes } = require('@joplin/lib/path-utils');
|
||||||
|
|
||||||
@@ -262,7 +263,7 @@ export function findMatchingRoute(path: string, routes: Routers): MatchedRoute {
|
|||||||
// Create the base path, eg. "api/files", to match it to one of the
|
// Create the base path, eg. "api/files", to match it to one of the
|
||||||
// routes.
|
// routes.
|
||||||
const basePath = `${namespace ? `${namespace}/` : ''}${splittedPath[0]}/${splittedPath[1]}`;
|
const basePath = `${namespace ? `${namespace}/` : ''}${splittedPath[0]}/${splittedPath[1]}`;
|
||||||
if (routes[basePath]) {
|
if (hasOwnProperty(routes, basePath)) {
|
||||||
// Remove the base path from the array so that parseSubPath() can
|
// Remove the base path from the array so that parseSubPath() can
|
||||||
// extract the ID and link from the URL. So the array will contain
|
// extract the ID and link from the URL. So the array will contain
|
||||||
// at this point: ['SOME_ID', 'content'].
|
// at this point: ['SOME_ID', 'content'].
|
||||||
@@ -278,7 +279,7 @@ export function findMatchingRoute(path: string, routes: Routers): MatchedRoute {
|
|||||||
// Paths such as "/users/:id" or "/apps/joplin/notes/:id" will get here
|
// Paths such as "/users/:id" or "/apps/joplin/notes/:id" will get here
|
||||||
const basePath = splittedPath[0];
|
const basePath = splittedPath[0];
|
||||||
const basePathNS = (namespace ? `${namespace}/` : '') + basePath;
|
const basePathNS = (namespace ? `${namespace}/` : '') + basePath;
|
||||||
if (routes[basePathNS]) {
|
if (hasOwnProperty(routes, basePathNS)) {
|
||||||
splittedPath.splice(0, 1);
|
splittedPath.splice(0, 1);
|
||||||
return {
|
return {
|
||||||
route: routes[basePathNS],
|
route: routes[basePathNS],
|
||||||
|
|||||||
@@ -15,3 +15,7 @@ export function checkObjectHasProperties(object: any, properties: string[]) {
|
|||||||
if (!(prop in object)) throw new Error(`Missing property "${prop}": ${JSON.stringify(object)}`);
|
if (!(prop in object)) throw new Error(`Missing property "${prop}": ${JSON.stringify(object)}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const hasOwnProperty = (object: object, property: string): boolean => {
|
||||||
|
return !!object && Object.prototype.hasOwnProperty.call(object, property);
|
||||||
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user