mirror of
https://github.com/TriliumNext/Notes.git
synced 2026-01-07 05:19:53 -06:00
fixed: mixed custom url and bare domain redirect
Previous commit contained mishmash of the abandoned custom share and login redirect urls and simple bare domain redirect. Simply put: was broken and didn't work. Todo: test with a new setup and no initialised db.
This commit is contained in:
@@ -17,7 +17,7 @@ const TPL = `
|
||||
<div class="custom-control custom-checkbox">
|
||||
<input class="custom-control-input show-login-in-share" type="checkbox" id="showLoginInShare">
|
||||
<label class="custom-control-label" for="showLoginInShare">${t('share.show_login_in_share')}</label>
|
||||
<p>${t('share.show_login_in_share_description')}</p>
|
||||
<p>${t('share.show_login_in_share_description', { hostname: window.location.hostname })}</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -1566,6 +1566,6 @@
|
||||
"redirect_bare_domain": "Redirect bare domain to share",
|
||||
"redirect_bare_domain_description": "When enabled, accessing the root URL (/) will redirect to the share page (/share). Relies on having one more more notes shared, and one having `#shareRoot` attribute defined. (default: false)",
|
||||
"show_login_in_share": "Show login in share theme",
|
||||
"show_login_in_share_description": "When enabled, shows a login button in the share theme (default: false). Probably best to leave it disabled and visit 'my-domain.net/login' manually to login."
|
||||
"show_login_in_share_description": "When enabled, shows a login button in the share theme (default: false). Probably best to leave it disabled and visit '{{hostname}}/login' manually to login."
|
||||
}
|
||||
}
|
||||
|
||||
@@ -68,8 +68,7 @@ export const ALLOWED_OPTIONS = new Set([
|
||||
'firstDayOfWeek',
|
||||
'textNoteEditorType',
|
||||
'layoutOrientation',
|
||||
'shareRedirectUrl',
|
||||
'loginRedirectUrl',
|
||||
'redirectBareDomain',
|
||||
'showLoginInShareTheme'
|
||||
]);
|
||||
|
||||
|
||||
@@ -15,6 +15,7 @@ import rateLimit from "express-rate-limit";
|
||||
import AbstractBeccaEntity from "../becca/entities/abstract_becca_entity.js";
|
||||
import NotFoundError from "../errors/not_found_error.js";
|
||||
import ValidationError from "../errors/validation_error.js";
|
||||
import optionService from '../services/options.js';
|
||||
|
||||
// page routes
|
||||
import setupRoute from "./setup.js";
|
||||
@@ -54,7 +55,7 @@ import clipperRoute from "./api/clipper.js";
|
||||
import similarNotesRoute from "./api/similar_notes.js";
|
||||
import keysRoute from "./api/keys.js";
|
||||
import backendLogRoute from "./api/backend_log.js";
|
||||
import statsRoute from "../stats/stats.js";
|
||||
import statsRoute from "./api/stats.js";
|
||||
import fontsRoute from "./api/fonts.js";
|
||||
import etapiTokensApiRoutes from "./api/etapi_tokens.js";
|
||||
import relationMapApiRoute from "./api/relation-map.js";
|
||||
@@ -102,15 +103,6 @@ const uploadMiddlewareWithErrorHandling = function (req: express.Request, res: e
|
||||
};
|
||||
|
||||
function register(app: express.Application) {
|
||||
// Add bare domain redirect handler
|
||||
app.use((req, res, next) => {
|
||||
if (req.path === '/' && optionService.getOption('redirectBareDomain')) {
|
||||
res.redirect('/share');
|
||||
} else {
|
||||
next();
|
||||
}
|
||||
});
|
||||
|
||||
route(GET, '/', [auth.checkAuth, csrfMiddleware], indexRoute.index);
|
||||
route(GET, '/login', [auth.checkAppInitialized, auth.checkPasswordSet], loginRoute.loginPage);
|
||||
route(GET, '/set-password', [auth.checkAppInitialized, auth.checkPasswordNotSet], loginRoute.setPasswordPage);
|
||||
@@ -118,7 +110,7 @@ function register(app: express.Application) {
|
||||
const loginRateLimiter = rateLimit({
|
||||
windowMs: 15 * 60 * 1000, // 15 minutes
|
||||
max: 10, // limit each IP to 10 requests per windowMs
|
||||
skipSuccessfulRequests: true // successful auth to rate-limited ETAPI routes isn't counted. However, successful auth to /login is still counted!
|
||||
skipSuccessfulRequests: true, // successful auth to rate-limited ETAPI routes isn't counted. However, successful auth to /login is still counted!
|
||||
message: 'Too many login attempts, please try again later.',
|
||||
standardHeaders: true, // Return rate limit info in the `RateLimit-*` headers
|
||||
legacyHeaders: false // Disable the `X-RateLimit-*` headers
|
||||
|
||||
@@ -14,12 +14,12 @@ import optionService from "./options.js";
|
||||
const noAuthentication = config.General && config.General.noAuthentication === true;
|
||||
|
||||
function checkAuth(req: AppRequest, res: Response, next: NextFunction) {
|
||||
if (!sqlInit.isDbInitialized()) {
|
||||
res.redirect("setup");
|
||||
}
|
||||
else if (!req.session.loggedIn && !utils.isElectron() && !noAuthentication) {
|
||||
const shareRedirectUrl = optionService.getOption('shareRedirectUrl');
|
||||
res.redirect(shareRedirectUrl);
|
||||
if (!req.session.loggedIn && !utils.isElectron() && !noAuthentication) {
|
||||
if (optionService.getOption('redirectBareDomain') === 'true') {
|
||||
res.redirect('/share');
|
||||
} else {
|
||||
res.redirect('login');
|
||||
}
|
||||
}
|
||||
else {
|
||||
next();
|
||||
|
||||
@@ -102,6 +102,7 @@ const defaultOptions: DefaultOption[] = [
|
||||
{ name: 'headingStyle', value: 'underline', isSynced: true },
|
||||
{ name: 'autoCollapseNoteTree', value: 'true', isSynced: true },
|
||||
{ name: 'autoReadonlySizeText', value: '10000', isSynced: false },
|
||||
{ name: 'redirectBareDomain', value: 'false', isSynced: true },
|
||||
{ name: 'autoReadonlySizeCode', value: '30000', isSynced: false },
|
||||
{ name: 'dailyBackupEnabled', value: 'true', isSynced: false },
|
||||
{ name: 'weeklyBackupEnabled', value: 'true', isSynced: false },
|
||||
|
||||
Reference in New Issue
Block a user