diff --git a/BUILD.txt b/BUILD.txt new file mode 100644 index 0000000..090a256 --- /dev/null +++ b/BUILD.txt @@ -0,0 +1,8 @@ +##### FRONT END ##### +git clone git@ssh.dev.azure.com:v3/HackKu/HackKu%202020/frontend frontend +cd frontend +npm i +ionic build --prod +tar czvf target-www.tar.gz ./www + +##### target-www.tar.gz is the artifact! ##### diff --git a/Units.flitter.js b/Units.flitter.js index bd7a664..c29ccf5 100644 --- a/Units.flitter.js +++ b/Units.flitter.js @@ -61,6 +61,7 @@ const FlitterUnits = { * Custom units should be specified here. They will be loaded in order * after the core of Flitter has been initialized. */ + 'Ionic' : require('./app/IonicUnit'), // 'CustomUnit' : new CustomUnit(), /* diff --git a/app/IonicUnit.js b/app/IonicUnit.js new file mode 100644 index 0000000..788305b --- /dev/null +++ b/app/IonicUnit.js @@ -0,0 +1,40 @@ +const Unit = require('libflitter/Unit') +const cors = require('cors') +const Express = require('express') +const path = require('path') + +class IonicUnit extends Unit { + static get services() { + return [...super.services, 'configs', 'express', 'canon', 'utility'] + } + + 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', [ + this.canon.get('middleware::auth:UserOnly'), + (req, res, next) => { + const allowed_extensions = ['.html', '.js', '.css', '.svg', '.ttf', '.jpg', '.png', '.jpeg'] + 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), + ]) + } + +} + +module.exports = exports = IonicUnit diff --git a/config/ionic.config.js b/config/ionic.config.js new file mode 100644 index 0000000..76ae3d5 --- /dev/null +++ b/config/ionic.config.js @@ -0,0 +1,9 @@ +// ionic Configuration +const ionic = { + + // Path to the root of the ionic app from the root of the Flitter app + root: 'www', + +} + +module.exports = exports = ionic diff --git a/package.json b/package.json index d6e4f31..feb6b14 100644 --- a/package.json +++ b/package.json @@ -16,6 +16,7 @@ "author": "Garrett Mills (https://garrettmills.dev/)", "license": "MIT", "dependencies": { + "cors": "^2.8.5", "flitter-auth": "^0.18.0", "flitter-cli": "^0.15.2", "flitter-di": "^0.4.1", diff --git a/www/.gitkeep b/www/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/www/index.html b/www/index.html new file mode 100644 index 0000000..d97103d --- /dev/null +++ b/www/index.html @@ -0,0 +1,10 @@ + + + + + Missing Frontend + + +

You have not deployed the front-end to this application.

+ + diff --git a/yarn.lock b/yarn.lock index 62e2ef7..8bc4183 100644 --- a/yarn.lock +++ b/yarn.lock @@ -648,6 +648,14 @@ core-util-is@~1.0.0: resolved "https://registry.yarnpkg.com/core-util-is/-/core-util-is-1.0.2.tgz#b5fd54220aa2bc5ab57aab7140c940754503c1a7" integrity sha1-tf1UIgqivFq1eqtxQMlAdUUDwac= +cors@^2.8.5: + version "2.8.5" + resolved "https://registry.yarnpkg.com/cors/-/cors-2.8.5.tgz#eac11da51592dd86b9f06f6e7ac293b3df875d29" + integrity sha512-KIHbLJqu73RGr/hnbrO9uBeixNGuvSQjul/jdFvS/KFSIH1hWVd1ng7zOHx+YrEfInLG7q4n6GHQ9cDtxv/P6g== + dependencies: + object-assign "^4" + vary "^1" + dashdash@1.7.3: version "1.7.3" resolved "https://registry.yarnpkg.com/dashdash/-/dashdash-1.7.3.tgz#bf533fedaa455ed8fee11519ebfb9ad66170dcdf" @@ -1970,7 +1978,7 @@ number-is-nan@^1.0.0: resolved "https://registry.yarnpkg.com/number-is-nan/-/number-is-nan-1.0.1.tgz#097b602b53422a522c1afb8790318336941a011d" integrity sha1-CXtgK1NCKlIsGvuHkDGDNpQaAR0= -object-assign@^4.0.1, object-assign@^4.1.0: +object-assign@^4, object-assign@^4.0.1, object-assign@^4.1.0: version "4.1.1" resolved "https://registry.yarnpkg.com/object-assign/-/object-assign-4.1.1.tgz#2109adc7965887cfc05cbbd442cac8bfbb360863" integrity sha1-IQmtx5ZYh8/AXLvUQsrIv7s2CGM= @@ -2889,7 +2897,7 @@ validator@^10.11.0: resolved "https://registry.yarnpkg.com/validator/-/validator-10.11.0.tgz#003108ea6e9a9874d31ccc9e5006856ccd76b228" integrity sha512-X/p3UZerAIsbBfN/IwahhYaBbY68EN/UQBWHtsbXGT5bfrH/p4NQzUCG1kF/rtKaNpnJ7jAu6NGTdSNtyNIXMw== -vary@~1.1.2: +vary@^1, vary@~1.1.2: version "1.1.2" resolved "https://registry.yarnpkg.com/vary/-/vary-1.1.2.tgz#2299f02c6ded30d4a5961b0b9f74524a18f634fc" integrity sha1-IpnwLG3tMNSllhsLn3RSShj2NPw=