2016-03-19 21:37:04 +01:00
|
|
|
'use strict';
|
|
|
|
|
2016-04-07 21:12:59 +02:00
|
|
|
require('./util/polyfill.js');
|
2016-06-11 17:41:28 +02:00
|
|
|
const misc = require('./util/misc.js');
|
2016-06-14 10:31:48 +02:00
|
|
|
const views = require('./util/views.js');
|
2016-06-12 20:11:43 +02:00
|
|
|
const router = require('./router.js');
|
|
|
|
|
2016-06-12 21:58:05 +02:00
|
|
|
history.scrollRestoration = 'manual';
|
2016-05-08 18:56:08 +02:00
|
|
|
|
2016-06-12 20:11:43 +02:00
|
|
|
router.exit(
|
2017-01-20 21:51:04 +01:00
|
|
|
null,
|
2016-06-12 20:11:43 +02:00
|
|
|
(ctx, next) => {
|
2016-06-12 21:58:05 +02:00
|
|
|
ctx.state.scrollX = window.scrollX;
|
|
|
|
ctx.state.scrollY = window.scrollY;
|
2016-07-08 00:46:48 +02:00
|
|
|
router.replace(router.url, ctx.state);
|
2016-06-12 20:11:43 +02:00
|
|
|
if (misc.confirmPageExit()) {
|
|
|
|
next();
|
|
|
|
}
|
|
|
|
});
|
2016-06-11 17:41:28 +02:00
|
|
|
|
2016-04-14 21:01:33 +02:00
|
|
|
const mousetrap = require('mousetrap');
|
2016-06-12 20:11:43 +02:00
|
|
|
router.enter(
|
2017-01-20 21:51:04 +01:00
|
|
|
null,
|
2016-06-12 20:11:43 +02:00
|
|
|
(ctx, next) => {
|
|
|
|
mousetrap.reset();
|
|
|
|
next();
|
|
|
|
});
|
2016-04-14 21:01:33 +02:00
|
|
|
|
2016-06-14 10:31:48 +02:00
|
|
|
const tags = require('./tags.js');
|
2016-04-08 10:01:32 +02:00
|
|
|
const api = require('./api.js');
|
2018-06-25 16:47:20 +02:00
|
|
|
|
|
|
|
api.fetchConfig().then(() => {
|
|
|
|
// register controller routes
|
|
|
|
let controllers = [];
|
|
|
|
controllers.push(require('./controllers/home_controller.js'));
|
|
|
|
controllers.push(require('./controllers/help_controller.js'));
|
|
|
|
controllers.push(require('./controllers/auth_controller.js'));
|
|
|
|
controllers.push(require('./controllers/password_reset_controller.js'));
|
|
|
|
controllers.push(require('./controllers/comments_controller.js'));
|
|
|
|
controllers.push(require('./controllers/snapshots_controller.js'));
|
|
|
|
controllers.push(require('./controllers/post_detail_controller.js'));
|
|
|
|
controllers.push(require('./controllers/post_main_controller.js'));
|
|
|
|
controllers.push(require('./controllers/post_list_controller.js'));
|
|
|
|
controllers.push(require('./controllers/post_upload_controller.js'));
|
|
|
|
controllers.push(require('./controllers/tag_controller.js'));
|
|
|
|
controllers.push(require('./controllers/tag_list_controller.js'));
|
|
|
|
controllers.push(require('./controllers/tag_categories_controller.js'));
|
|
|
|
controllers.push(require('./controllers/settings_controller.js'));
|
|
|
|
controllers.push(require('./controllers/user_controller.js'));
|
|
|
|
controllers.push(require('./controllers/user_list_controller.js'));
|
|
|
|
controllers.push(require('./controllers/user_registration_controller.js'));
|
|
|
|
|
|
|
|
// 404 controller needs to be registered last
|
|
|
|
controllers.push(require('./controllers/not_found_controller.js'));
|
|
|
|
|
|
|
|
for (let controller of controllers) {
|
|
|
|
controller(router);
|
|
|
|
}
|
|
|
|
}, error => {
|
|
|
|
window.alert('Could not fetch basic configuration from server');
|
|
|
|
}).then(() => {
|
|
|
|
api.loginFromCookies().then(() => {
|
2020-06-04 20:09:35 +02:00
|
|
|
tags.refreshCategoryColorMap();
|
|
|
|
router.start();
|
|
|
|
}, error => {
|
|
|
|
if (window.location.href.indexOf('login') !== -1) {
|
|
|
|
api.forget();
|
2016-06-12 20:11:43 +02:00
|
|
|
router.start();
|
2020-06-04 20:09:35 +02:00
|
|
|
} else {
|
|
|
|
const ctx = router.start('/');
|
|
|
|
ctx.controller.showError(
|
|
|
|
'An error happened while trying to log you in: ' +
|
2018-06-25 16:47:20 +02:00
|
|
|
error.message);
|
2020-06-04 20:09:35 +02:00
|
|
|
}
|
|
|
|
});
|
2018-06-25 16:47:20 +02:00
|
|
|
});
|