Add structure for adding exported Ionic application to backend server
55b0b123
garrettmills
committed
8 changed files
IonicUnit.js
/app/IonicUnit.js+41
/app/IonicUnit.js
Add comment 1 Plus  const Unit = require('libflitter/Unit')
Add comment 2 Plus  const cors = require('cors')
Add comment 3 Plus  const Express = require('express')
Add comment 4 Plus  const path = require('path')
Add comment 5 Plus  
Add comment 6 Plus  class IonicUnit extends Unit {
Add comment 7 Plus   static get services() {
Add comment 8 Plus   return [...super.services, 'configs', 'express', 'canon', 'utility']
Add comment 9 Plus   }
Add comment 10 Plus  
Add comment 11 Plus   constructor(...args) {
Add comment 12 Plus   super(...args)
Add comment 13 Plus  
Add comment 14 Plus   /**
Add comment 15 Plus   * Fully qualified path to the root of the ionic app.
Add comment 16 Plus   * @type {string}
Add comment 17 Plus   */
Add comment 18 Plus   this.directory = path.resolve(path.dirname(this.utility.root()), this.configs.get('ionic.root'))
Add comment 19 Plus   }
Add comment 20 Plus  
Add comment 21 Plus   async go(app) {
Add comment 22 Plus   app.express.use(cors())
Add comment 23 Plus  
Add comment 24 Plus   app.express.use('/i', [
Add comment 25 Plus   this.canon.get('middleware::auth:UserOnly'),
Add comment 26 Plus   (req, res, next) => {
Add comment 27 Plus   const allowed_extensions = ['.html', '.js', '.css', '.svg', '.ttf', '.jpg', '.png', '.jpeg']
Add comment 28 Plus   for ( const k1 in allowed_extensions ) {
Add comment 29 Plus   if ( req.path.endsWith(allowed_extensions[k1]) ) return next()
Add comment 30 Plus   }
Add comment 31 Plus  
Add comment 32 Plus   return res.sendFile(path.resolve(this.directory, 'index.html'))
Add comment 33 Plus   },
Add comment 34 Plus   Express.static(this.directory),
Add comment 35 Plus   ])
Add comment 36 Plus   }
Add comment 37 Plus  
Add comment 38 Plus  }
Add comment 39 Plus  
Add comment 40 Plus  module.exports = exports = IonicUnit
Add comment 41 Plus  
ionic.config.js
/config/ionic.config.js+10
/config/ionic.config.js
Add comment 1 Plus  // ionic Configuration
Add comment 2 Plus  const ionic = {
Add comment 3 Plus  
Add comment 4 Plus   // Path to the root of the ionic app from the root of the Flitter app
Add comment 5 Plus   root: 'www',
Add comment 6 Plus  
Add comment 7 Plus  }
Add comment 8 Plus  
Add comment 9 Plus  module.exports = exports = ionic
Add comment 10 Plus  
.gitkeep
/www/.gitkeep
/www/.gitkeep
index.html
/www/index.html
/www/index.html
BUILD.txt
/BUILD.txt
/BUILD.txt
package.json
/package.json
/package.json
Units.flitter.js
/Units.flitter.js
/Units.flitter.js
yarn.lock
/yarn.lock
/yarn.lock