1
0
mirror of https://github.com/laurent22/joplin.git synced 2024-11-24 08:12:24 +02:00

Server: Redirect to correct page when trying to access the root

This commit is contained in:
Laurent Cozic 2021-05-25 12:21:35 +02:00
parent b20ab19f13
commit 51051e0ee0

View File

@ -1,4 +1,4 @@
import { SubPath, Response, ResponseType } from '../utils/routeUtils';
import { SubPath, Response, ResponseType, redirect } from '../utils/routeUtils';
import Router from '../utils/Router';
import { ErrorNotFound, ErrorForbidden } from '../utils/errors';
import { dirname, normalize } from 'path';
@ -51,6 +51,15 @@ router.public = true;
// Used to serve static files, so it needs to be public because for example the
// login page, which is public, needs access to the CSS files.
router.get('', async (path: SubPath, ctx: AppContext) => {
// Redirect to either /login or /home when trying to access the root
if (!path.id && !path.link) {
if (ctx.owner) {
return redirect(ctx, 'home');
} else {
return redirect(ctx, 'login');
}
}
const localPath = await findLocalFile(path.raw);
let mimeType: string = mime.fromFilename(localPath);