2020-02-08 02:34:04 +00:00
|
|
|
const Unit = require('libflitter/Unit')
|
|
|
|
const cors = require('cors')
|
|
|
|
const Express = require('express')
|
|
|
|
const path = require('path')
|
|
|
|
|
|
|
|
class IonicUnit extends Unit {
|
|
|
|
static get services() {
|
2020-10-13 02:46:50 +00:00
|
|
|
return [...super.services, 'configs', 'express', 'canon', 'utility', 'scaffold']
|
2020-02-08 02:34:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
constructor(...args) {
|
|
|
|
super(...args)
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Fully qualified path to the root of the ionic app.
|
|
|
|
* @type {string}
|
|
|
|
*/
|
|
|
|
this.directory = path.resolve(path.dirname(this.utility.root()), this.configs.get('ionic.root'))
|
|
|
|
}
|
|
|
|
|
|
|
|
async go(app) {
|
|
|
|
app.express.use(cors())
|
|
|
|
|
|
|
|
app.express.use('/i', [
|
2020-02-09 05:15:36 +00:00
|
|
|
this.canon.get('middleware::auth:UserOnly'),
|
2020-02-08 02:34:04 +00:00
|
|
|
(req, res, next) => {
|
2020-10-22 14:41:29 +00:00
|
|
|
const allowed_extensions = [
|
|
|
|
'.html', '.js', '.css', '.svg', '.ttf', '.jpg', '.png',
|
|
|
|
'.jpeg', '.webmanifest', '.json', '.eot', '.svg', '.cur',
|
|
|
|
'.webp', '.gif', '.otf', '.woff', '.woff2', '.ani', '.map',
|
|
|
|
'.ico',
|
|
|
|
]
|
2020-02-08 02:34:04 +00:00
|
|
|
for ( const k1 in allowed_extensions ) {
|
|
|
|
if ( req.path.endsWith(allowed_extensions[k1]) ) return next()
|
|
|
|
}
|
|
|
|
|
|
|
|
return res.sendFile(path.resolve(this.directory, 'index.html'))
|
|
|
|
},
|
|
|
|
Express.static(this.directory),
|
|
|
|
])
|
2020-10-13 02:46:50 +00:00
|
|
|
|
|
|
|
// Create the full-text search indices
|
|
|
|
const pages = this.scaffold.collection('api_Page')
|
|
|
|
await pages.createIndex({ Name: 'text' })
|
|
|
|
|
|
|
|
const nodes = this.scaffold.collection('api_Node')
|
|
|
|
await nodes.createIndex({ 'Value.Value': 'text' })
|
|
|
|
|
|
|
|
const databases = this.scaffold.collection('api_db_Database')
|
|
|
|
await databases.createIndex({ Name: 'text' })
|
2020-02-08 02:34:04 +00:00
|
|
|
|
2020-10-13 14:24:28 +00:00
|
|
|
const codiums = this.scaffold.collection('api_Codium')
|
|
|
|
await codiums.createIndex({ code: 'text' })
|
2020-10-14 18:59:25 +00:00
|
|
|
|
|
|
|
const files = this.scaffold.collection('upload__File')
|
|
|
|
await files.createIndex({ original_name: 'text' })
|
2020-10-13 14:24:28 +00:00
|
|
|
}
|
2020-02-08 02:34:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = exports = IonicUnit
|