|
|
@@ -308,16 +308,55 @@ module.exports = function(crowi, app) {
|
|
|
})
|
|
|
// page not exists
|
|
|
.catch(function(err) {
|
|
|
- const pageName = originalUrl.replace(/^\/([^/]*).*$/, '$1');
|
|
|
+ const pageName = originalUrl.replace(/^\/([^\/]*).*$/, '$1');
|
|
|
Page.findPage(`/${pageName}/_template`)
|
|
|
.then(function(page) {
|
|
|
- debug('Page not found', path);
|
|
|
- console.log('---------------------------template found');
|
|
|
- pageTeamplate = 'customlayout-selector/not_found';
|
|
|
+ //new page object and do as when found
|
|
|
+ var templateRevision = page.revision;
|
|
|
+
|
|
|
+ var templatePage = new Page();
|
|
|
+ templatePage.path = originalUrl;
|
|
|
+ templatePage.creator = req.user;
|
|
|
+ templatePage.lastUpdateUser = req.user;
|
|
|
+ templatePage.createdAt = Date.now();
|
|
|
+ templatePage.updatedAt = Date.now();
|
|
|
+ templatePage.redirectTo = null;
|
|
|
+ templatePage.grant = 1;
|
|
|
+ templatePage.status = 'published';
|
|
|
+ templatePage.grantedUsers = [];
|
|
|
+ templatePage.grantedUsers.push(req.user);
|
|
|
+
|
|
|
+ renderVars.page = templatePage;
|
|
|
+ renderVars.path = templatePage.path;
|
|
|
+ renderVars.revision = templateRevision;
|
|
|
+ renderVars.author = templatePage.revision.author;
|
|
|
+
|
|
|
+ // redirect
|
|
|
+ if (page.redirectTo) {
|
|
|
+ debug(`Redirect to '${page.redirectTo}'`);
|
|
|
+ isRedirect = true;
|
|
|
+ return res.redirect(encodeURI(page.redirectTo + '?redirectFrom=' + pagePathUtil.encodePagePath(page.path)));
|
|
|
+ }
|
|
|
+
|
|
|
+ renderVars.page = templatePage;
|
|
|
+
|
|
|
+ if (page) {
|
|
|
+ renderVars.path = templatePage.path;
|
|
|
+ renderVars.revision = templateRevision;
|
|
|
+ renderVars.author = templatePage.revision.author;
|
|
|
+
|
|
|
+ // これいる??
|
|
|
+ return Revision.findRevisionList(page.path, {})
|
|
|
+ .then(function(tree) {
|
|
|
+ renderVars.tree = tree;
|
|
|
+ return Promise.resolve();
|
|
|
+ }).then(function() {
|
|
|
+ return Promise.resolve();
|
|
|
+ });
|
|
|
+ }
|
|
|
})
|
|
|
.catch(function(err) {
|
|
|
debug('Page not found', path);
|
|
|
- console.log('---------------------------not found');
|
|
|
// change template
|
|
|
pageTeamplate = 'customlayout-selector/not_found';
|
|
|
});
|