src/server/routes/get-main.js
function(req, res, next) {
  var filePath = req.originalUrl.replace('/abe/editor', '')
  if (filePath === '' || filePath === '/') {
    filePath = null
  }
  if (
    filePath != null &&
    path.extname(filePath) != `.${config.files.templates.extension}` &&
    path.extname(filePath) != '.json'
  ) {
    next()
    return
  }
  if (filePath != null) {
    var testXSS = xss(filePath, {
      whiteList: [],
      stripIgnoreTag: true
    })
    if (testXSS !== filePath) {
      filePath = testXSS
    }
  }

  abeExtend.hooks.instance.trigger('beforeRoute', req, res, next)
  if (typeof res._header !== 'undefined' && res._header !== null) return

  var isHome = true
  var jsonPath = null
  var template = null
  var fileName = null
  var folderPath = null

  var EditorVariables = {
    user: res.user,
    slugs: Manager.instance.getSlugs(),
    express: {
      res: res,
      req: req
    },
    filename: fileName,
    folderPath: folderPath,
    abeUrl: '/abe/editor/',
    isHome: isHome,
    config: config,
    Locales: coreUtils.locales.instance.i18n,
    abeVersion: pkg.version
  }

  let p = new Promise(resolve => {
    if (filePath != null) {
      fileName = path.basename(filePath)
      folderPath = path.dirname(filePath)

      EditorVariables.isHome = false
      EditorVariables.isEditor = true
      var filePathTest = cmsData.revision.getDocumentRevision(filePath)
      if (typeof filePathTest !== 'undefined' && filePathTest !== null) {
        jsonPath = filePathTest.path
        template = filePathTest.abe_meta.template
      }

      if (jsonPath === null || !coreUtils.file.exist(jsonPath)) {
        res.redirect('/abe/editor')
        return
      }

      var json = {}
      if (coreUtils.file.exist(jsonPath)) {
        json = cmsData.file.get(jsonPath, 'utf8')
      }
      var text = cmsTemplates.template.getTemplate(template, json)
      cmsEditor.editor
        .create(text, json)
        .then(result => {
          resolve(result)
        })
        .catch(function(e) {
          console.error(e)
        })
    } else {
      resolve({
        json: {},
        manager: {}
      })
    }
  }).catch(function(e) {
    console.error(e) // "oh, no!"
  })

  p
    .then(obj => {
      var precontribs = Manager.instance.getPrecontribution()
      var promises = []
      EditorVariables.resultPrecontrib = []
      if (precontribs != null) {
        Array.prototype.forEach.call(precontribs, precontrib => {
          var p = cmsEditor.editor
            .create(precontrib, obj.json, true)
            .then(resultPrecontrib => {
              EditorVariables.resultPrecontrib.push(resultPrecontrib)
            })
            .catch(function(e) {
              console.error(e)
            })
          promises.push(p)
        })
        Promise.all(promises)
          .then(() => {
            renderAbeAdmin(EditorVariables, obj, filePath, isHome, template)
          })
          .catch(function(e) {
            console.error('get-main.js getDataList', e.stack)
          })
      }
    })
    .catch(e => {
      console.log('error', e)
    })
}
function(req, res, next) {
  var filePath = req.originalUrl.replace('/abe/editor', '')
  if (filePath === '' || filePath === '/') {
    filePath = null
  }
  if (
    filePath != null &&
    path.extname(filePath) != `.${config.files.templates.extension}` &&
    path.extname(filePath) != '.json'
  ) {
    next()
    return
  }
  if (filePath != null) {
    var testXSS = xss(filePath, {
      whiteList: [],
      stripIgnoreTag: true
    })
    if (testXSS !== filePath) {
      filePath = testXSS
    }
  }

  abeExtend.hooks.instance.trigger('beforeRoute', req, res, next)
  if (typeof res._header !== 'undefined' && res._header !== null) return

  var isHome = true
  var jsonPath = null
  var template = null
  var fileName = null
  var folderPath = null

  var EditorVariables = {
    user: res.user,
    slugs: Manager.instance.getSlugs(),
    express: {
      res: res,
      req: req
    },
    filename: fileName,
    folderPath: folderPath,
    abeUrl: '/abe/editor/',
    isHome: isHome,
    config: config,
    Locales: coreUtils.locales.instance.i18n,
    abeVersion: pkg.version
  }

  let p = new Promise(resolve => {
    if (filePath != null) {
      fileName = path.basename(filePath)
      folderPath = path.dirname(filePath)

      EditorVariables.isHome = false
      EditorVariables.isEditor = true
      var filePathTest = cmsData.revision.getDocumentRevision(filePath)
      if (typeof filePathTest !== 'undefined' && filePathTest !== null) {
        jsonPath = filePathTest.path
        template = filePathTest.abe_meta.template
      }

      if (jsonPath === null || !coreUtils.file.exist(jsonPath)) {
        res.redirect('/abe/editor')
        return
      }

      var json = {}
      if (coreUtils.file.exist(jsonPath)) {
        json = cmsData.file.get(jsonPath, 'utf8')
      }
      var text = cmsTemplates.template.getTemplate(template, json)
      cmsEditor.editor
        .create(text, json)
        .then(result => {
          resolve(result)
        })
        .catch(function(e) {
          console.error(e)
        })
    } else {
      resolve({
        json: {},
        manager: {}
      })
    }
  }).catch(function(e) {
    console.error(e) // "oh, no!"
  })

  p
    .then(obj => {
      var precontribs = Manager.instance.getPrecontribution()
      var promises = []
      EditorVariables.resultPrecontrib = []
      if (precontribs != null) {
        Array.prototype.forEach.call(precontribs, precontrib => {
          var p = cmsEditor.editor
            .create(precontrib, obj.json, true)
            .then(resultPrecontrib => {
              EditorVariables.resultPrecontrib.push(resultPrecontrib)
            })
            .catch(function(e) {
              console.error(e)
            })
          promises.push(p)
        })
        Promise.all(promises)
          .then(() => {
            renderAbeAdmin(EditorVariables, obj, filePath, isHome, template)
          })
          .catch(function(e) {
            console.error('get-main.js getDataList', e.stack)
          })
      }
    })
    .catch(e => {
      console.log('error', e)
    })
}
function ( req , res , next ) { var filePath = req . originalUrl . replace ( '/abe/editor' , '' ) if ( filePath === '' || filePath === '/' ) { filePath = null } if ( filePath != null && path . extname ( filePath ) != ` ${ config . files . templates . extension } ` && path . extname ( filePath ) != '.json' ) { next ( ) return } if ( filePath != null ) { var testXSS = xss ( filePath , { whiteList : [ ] , stripIgnoreTag : true } ) if ( testXSS !== filePath ) { filePath = testXSS } } abeExtend . hooks . instance . trigger ( 'beforeRoute' , req , res , next ) if ( typeof res . _header !== 'undefined' && res . _header !== null ) return var isHome = true var jsonPath = null var template = null var fileName = null var folderPath = null var EditorVariables = { user : res . user , slugs : Manager . instance . getSlugs ( ) , express : { res : res , req : req } , filename : fileName , folderPath : folderPath , abeUrl : '/abe/editor/' , isHome : isHome , config : config , Locales : coreUtils . locales . instance . i18n , abeVersion : pkg . version } let p = new Promise ( resolve => { if ( filePath != null ) { fileName = path . basename ( filePath ) folderPath = path . dirname ( filePath ) EditorVariables . isHome = false EditorVariables . isEditor = true var filePathTest = cmsData . revision . getDocumentRevision ( filePath ) if ( typeof filePathTest !== 'undefined' && filePathTest !== null ) { jsonPath = filePathTest . path template = filePathTest . abe_meta . template } if ( jsonPath === null || ! coreUtils . file . exist ( jsonPath ) ) { res . redirect ( '/abe/editor' ) return } var json = { } if ( coreUtils . file . exist ( jsonPath ) ) { json = cmsData . file . get ( jsonPath , 'utf8' ) } var text = cmsTemplates . template . getTemplate ( template , json ) cmsEditor . editor . create ( text , json ) . then ( result => { resolve ( result ) } ) . catch ( function ( e ) { console . error ( e ) } ) } else { resolve ( { json : { } , manager : { } } ) } } ) . catch ( function ( e ) { console . error ( e ) // "oh, no!" } ) p . then ( obj => { var precontribs = Manager . instance . getPrecontribution ( ) var promises = [ ] EditorVariables . resultPrecontrib = [ ] if ( precontribs != null ) { Array . prototype . forEach . call ( precontribs , precontrib => { var p = cmsEditor . editor . create ( precontrib , obj . json , true ) . then ( resultPrecontrib => { EditorVariables . resultPrecontrib . push ( resultPrecontrib ) } ) . catch ( function ( e ) { console . error ( e ) } ) promises . push ( p ) } ) Promise . all ( promises ) . then ( ( ) => { renderAbeAdmin ( EditorVariables , obj , filePath , isHome , template ) } ) . catch ( function ( e ) { console . error ( 'get-main.js getDataList' , e . stack ) } ) } } ) . catch ( e => { console . log ( 'error' , e ) } ) }
This route returns the editor page as HTML
@param  {[type]}   req  [description]
@param  {[type]}   res  [description]
@param  {Function} next [description]
@return {[type]}        [description]
This route returns the editor page as HTML