diff --git a/packages/my-joy-images/package.json b/packages/my-joy-images/package.json index ba745578..5dbdea0c 100644 --- a/packages/my-joy-images/package.json +++ b/packages/my-joy-images/package.json @@ -1,6 +1,6 @@ { "name": "my-joy-images", - "version": "1.3.6", + "version": "1.4.0", "private": true, "license": "MPL-2.0", "repository": "github:yldio/joyent-portal", diff --git a/packages/my-joy-images/public/index.html b/packages/my-joy-images/public/index.html index 7894e74b..94f53067 100644 --- a/packages/my-joy-images/public/index.html +++ b/packages/my-joy-images/public/index.html @@ -13,6 +13,6 @@
- + diff --git a/packages/my-joy-instances/package.json b/packages/my-joy-instances/package.json index 6d289c79..06e2c7b4 100644 --- a/packages/my-joy-instances/package.json +++ b/packages/my-joy-instances/package.json @@ -1,6 +1,6 @@ { "name": "my-joy-instances", - "version": "2.2.6", + "version": "2.3.0", "private": true, "license": "MPL-2.0", "repository": "github:yldio/joyent-portal", diff --git a/packages/my-joy-instances/public/index.html b/packages/my-joy-instances/public/index.html index 4e985743..eb081571 100644 --- a/packages/my-joy-instances/public/index.html +++ b/packages/my-joy-instances/public/index.html @@ -13,6 +13,6 @@
- + diff --git a/packages/my-joy-navigation/lib/index.js b/packages/my-joy-navigation/lib/index.js index 03f59079..324fb494 100644 --- a/packages/my-joy-navigation/lib/index.js +++ b/packages/my-joy-navigation/lib/index.js @@ -1,33 +1,90 @@ const Inert = require('inert'); const Path = require('path'); +const Url = require('url'); +const Intercept = require('apr-intercept'); +const Fs = require('mz/fs'); -const ROOT = Path.join(__dirname, '../build'); +const { NAMESPACE = 'navigation' } = process.env; exports.register = async server => { const manifest = require('../build/asset-manifest.json'); + const buildRoot = Path.join(__dirname, '../build'); + const buildStatic = Path.join(buildRoot, `${NAMESPACE}`); + const publicRoot = Path.join(__dirname, `../public/static`); - await server.register(Inert); + await server.register([ + { + plugin: Inert + } + ]); server.route([ { method: 'GET', - path: '/nav-static/{path*}', + path: `/${NAMESPACE}/service-worker.js`, config: { auth: false, - handler: (request, h) => { - const { params } = request; - const { path } = params; - - const file = manifest[path]; - - if (!file) { - return h.continue; + handler: { + file: { + path: Path.join(__dirname, '../build/service-worker.js') } + } + } + }, + { + method: 'GET', + path: `/${NAMESPACE}/favicon.ico`, + config: { + auth: false, + handler: { + file: { + path: Path.join(__dirname, '../build/favicon.ico') + } + } + } + }, + { + method: 'GET', + path: `/${NAMESPACE}/static/{rest*}`, + config: { + auth: false + }, + handler: async (request, h) => { + const { params } = request; + const { rest } = params; - return h.file(Path.join(ROOT, file), { - confine: ROOT + const publicPathname = Path.join(publicRoot, rest); + const [err1] = await Intercept( + Fs.access(publicPathname, Fs.constants.R_OK) + ); + + console.log({ publicPathname }); + + if (!err1) { + return h.file(publicPathname, { + confine: publicRoot }); } + + const buildMapPathname = Path.join(buildRoot, manifest[rest]); + const [err2] = await Intercept( + Fs.access(buildMapPathname, Fs.constants.R_OK) + ); + + console.log({ buildMapPathname }); + + if (!err2) { + return h.file(buildMapPathname, { + confine: buildStatic + }); + } + + console.log({ buildPathname }); + + const buildPathname = Path.join(buildStatic, rest); + return h.file(buildPathname, { + confine: buildStatic + }); } } ]); diff --git a/packages/my-joy-navigation/package.json b/packages/my-joy-navigation/package.json index 3c96e3e1..3b74c65f 100644 --- a/packages/my-joy-navigation/package.json +++ b/packages/my-joy-navigation/package.json @@ -1,15 +1,15 @@ { "name": "my-joy-navigation", - "version": "2.2.0", + "version": "2.3.1", "private": true, "license": "MPL-2.0", "main": "lib/index.js", "scripts": { - "dev": "NODE_ENV=development PREACT=1 REACT_APP_GQL_PORT=4000 PORT=3000 joyent-react-scripts start", + "dev": "NAMESPACE=navigation NODE_ENV=development PREACT=1 REACT_APP_GQL_PORT=3068 PORT=3000 joyent-react-scripts start", "build:test": "echo 0", "build:lib": "echo 0", - "build:bundle": "NODE_ENV=production redrun build", - "prepublish": "NODE_ENV=production redrun build", + "build:bundle": "NAMESPACE=navigation NODE_ENV=production redrun build", + "prepublish": "NAMESPACE=navigation NODE_ENV=production redrun build", "lint": "redrun lint:ci -- --fix", "lint:ci": "NODE_ENV=test eslint . --ext .js --ext .md", "test": "echo 0", @@ -22,6 +22,7 @@ "apollo-link": "^1.2.1", "apollo-link-http": "^1.5.2", "apollo-link-state": "^0.4.0", + "apr-intercept": "^3.0.3", "emotion": "^8.0.12", "emotion-theming": "^8.0.12", "graphql-tag": "^2.8.0", @@ -29,9 +30,10 @@ "joyent-icons": "^5.1.0", "joyent-ui-toolkit": "^6.0.0", "lodash.chunk": "^4.2.0", + "lodash.groupby": "^4.6.0", "lodash.keys": "^4.2.0", + "mz": "^2.7.0", "outy": "^0.1.2", - "param-case": "^2.1.1", "pascal-case": "^2.0.1", "preact": "^8.2.7", "preact-compat": "^3.18.0", diff --git a/packages/my-joy-navigation/public/index.html b/packages/my-joy-navigation/public/index.html index 4ff20351..242b419e 100644 --- a/packages/my-joy-navigation/public/index.html +++ b/packages/my-joy-navigation/public/index.html @@ -6,7 +6,7 @@