feat: support ssr on bundle

This commit is contained in:
Sérgio Ramos 2018-05-07 13:33:08 +01:00
parent 3f75f812fa
commit 0ae1290a5e
18 changed files with 204 additions and 89 deletions

View File

@ -1,7 +1,9 @@
const Main = require('apr-main');
const CloudApiGql = require('cloudapi-gql');
const Url = require('url');
const Server = require('./server');
const Ui = require('my-joy-images');
const {
PORT = 4003,
@ -25,19 +27,24 @@ Main(async () => {
BASE_URL
});
await server.register({
plugin: CloudApiGql,
options: {
authStrategy: 'sso',
keyPath,
keyId,
apiBaseUrl,
dcName
await server.register([
{
plugin: CloudApiGql,
options: {
authStrategy: 'sso',
keyPath,
keyId,
apiBaseUrl,
dcName
},
routes: {
prefix: `/${PREFIX}`
}
},
routes: {
prefix: `/${PREFIX}`
{
plugin: Ui
}
});
]);
await server.start();
});

View File

@ -1,7 +1,9 @@
const Main = require('apr-main');
const CloudApiGql = require('cloudapi-gql');
const Url = require('url');
const Server = require('./server');
const Ui = require('my-joy-instances');
const {
PORT = 4002,
@ -25,19 +27,24 @@ Main(async () => {
BASE_URL
});
await server.register({
plugin: CloudApiGql,
options: {
authStrategy: 'sso',
keyPath,
keyId,
apiBaseUrl,
dcName
await server.register([
{
plugin: CloudApiGql,
options: {
authStrategy: 'sso',
keyPath,
keyId,
apiBaseUrl,
dcName
},
routes: {
prefix: `/${PREFIX}`
}
},
routes: {
prefix: `/${PREFIX}`
{
plugin: Ui
}
});
]);
await server.start();
});

View File

@ -1,7 +1,9 @@
const Main = require('apr-main');
const Nav = require('hapi-webconsole-nav');
const Url = require('url');
const Server = require('./server');
const Ui = require('my-joy-navigation');
const Regions = require('../data/regions');
const Categories = require('../data/categories');
@ -30,22 +32,27 @@ Main(async () => {
BASE_URL
});
await server.register({
plugin: Nav,
options: {
keyPath,
keyId,
apiBaseUrl,
dcName,
baseUrl,
regions: Regions,
accountServices: Account,
categories: Categories
await server.register([
{
plugin: Nav,
options: {
keyPath,
keyId,
apiBaseUrl,
dcName,
baseUrl,
regions: Regions,
accountServices: Account,
categories: Categories
},
routes: {
prefix: `/${PREFIX}`
}
},
routes: {
prefix: `/${PREFIX}`
{
plugin: Ui
}
});
]);
await server.start();
});

View File

@ -6,6 +6,7 @@
"repository": "github:yldio/joyent-portal",
"scripts": {
"dev": "lerna run dev --parallel --stream",
"ssr": "npm run build:bundle; lerna run dev --scope joyent-portal-bundle --stream",
"test": "redrun -s build:test test:run",
"test:ci": "CI=1 redrun -s build:test test:ci:run",
"lint": "lerna run lint --stream",

View File

@ -1,3 +1,4 @@
const Boom = require('boom');
const Inert = require('inert');
const Path = require('path');
const RenderReact = require('hapi-render-react');
@ -8,8 +9,21 @@ const Fs = require('mz/fs');
const { NAMESPACE = 'images' } = process.env;
exports.register = async server => {
let manifest = {};
try {
manifest = require('../build/asset-manifest.json');
} catch (err) {
if (NODE_ENV === 'production') {
throw err;
} else {
console.error(err);
}
}
const relativeTo = Path.join(__dirname, 'app');
const buildRoot = Path.join(__dirname, `../build/${NAMESPACE}/static/`);
const buildRoot = Path.join(__dirname, '../build');
const buildStatic = Path.join(buildRoot, `${NAMESPACE}`);
const publicRoot = Path.join(__dirname, `../public/static/`);
await server.register([
@ -56,15 +70,41 @@ exports.register = async server => {
const { params } = request;
const { rest } = params;
const publicPathname = Path.join(publicRoot, rest);
const buildPathname = Path.join(buildRoot, rest);
if (!rest) {
return Boom.notFound();
}
const [err] = await Intercept(
const publicPathname = Path.join(publicRoot, rest);
const [err1] = await Intercept(
Fs.access(publicPathname, Fs.constants.R_OK)
);
const file = err ? buildPathname : publicPathname;
return h.file(file, { confine: false });
if (!err1) {
return h.file(publicPathname, {
confine: publicRoot
});
}
const filename = manifest[rest];
if (!filename) {
return Boom.notFound();
}
const buildMapPathname = Path.join(buildRoot, filename);
const [err2] = await Intercept(
Fs.access(buildMapPathname, Fs.constants.R_OK)
);
if (!err2) {
return h.file(buildMapPathname, {
confine: buildStatic
});
}
const buildPathname = Path.join(buildStatic, rest);
return h.file(buildPathname, {
confine: buildStatic
});
}
},
{

View File

@ -26,6 +26,7 @@
"apollo-link-http": "^1.5.3",
"apr-intercept": "^3.0.3",
"apr-reduce": "^3.0.3",
"boom": "^7.2.0",
"cross-fetch": "^2.1.0",
"date-fns": "^1.29.0",
"declarative-redux-form": "^2.0.8",
@ -33,7 +34,7 @@
"force-array": "^3.1.0",
"fuse.js": "^3.2.0",
"hapi-render-react": "^2.5.2",
"hapi-render-react-joyent-document": "^7.0.1",
"hapi-render-react-joyent-document": "^7.1.0",
"inert": "^5.1.0",
"joyent-logo-assets": "^1.1.0",
"joyent-react-styled-flexboxgrid": "^2.2.3",

View File

@ -1,18 +0,0 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
<meta name="theme-color" content="#1E313B">
<!-- <link rel="manifest" href="%PUBLIC_URL%/manifest.json"> -->
<!-- <link rel="shortcut icon" href="%PUBLIC_URL%/favicon.ico"> -->
<title>My Joyent Images &beta;</title>
</head>
<body>
<div id="header"></div>
<div id="root"></div>
<script src="/navigation/static/main.js"></script>
</body>
</html>

View File

@ -1,11 +1,19 @@
const React = require('react');
module.exports = ({ htmlAttrs = {}, bodyAttrs = {}, head = [], children = null }) => (
module.exports = ({
htmlAttrs = {},
bodyAttrs = {},
head = [],
children = null
}) => (
<html {...htmlAttrs}>
<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" />
<meta charSet="utf-8" />
<meta httpEquiv="X-UA-Compatible" content="IE=edge" />
<meta
name="viewport"
content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no"
/>
<meta name="theme-color" content="#1E313B" />
{head}

View File

@ -1,3 +1,4 @@
const Boom = require('boom');
const Inert = require('inert');
const Path = require('path');
const RenderReact = require('hapi-render-react');
@ -6,11 +7,24 @@ const Url = require('url');
const Intercept = require('apr-intercept');
const Fs = require('mz/fs');
const { NAMESPACE = 'instances' } = process.env;
const { NAMESPACE = 'instances', NODE_ENV = 'development' } = process.env;
exports.register = async server => {
let manifest = {};
try {
manifest = require('../build/asset-manifest.json');
} catch (err) {
if (NODE_ENV === 'production') {
throw err;
} else {
console.error(err);
}
}
const relativeTo = Path.join(__dirname, 'app');
const buildRoot = Path.join(__dirname, `../build/${NAMESPACE}/static/`);
const buildRoot = Path.join(__dirname, '../build');
const buildStatic = Path.join(buildRoot, `${NAMESPACE}`);
const publicRoot = Path.join(__dirname, `../public/static/`);
await server.register([
@ -57,15 +71,41 @@ exports.register = async server => {
const { params } = request;
const { rest } = params;
const publicPathname = Path.join(publicRoot, rest);
const buildPathname = Path.join(buildRoot, rest);
if (!rest) {
return Boom.notFound();
}
const [err] = await Intercept(
const publicPathname = Path.join(publicRoot, rest);
const [err1] = await Intercept(
Fs.access(publicPathname, Fs.constants.R_OK)
);
const file = err ? buildPathname : publicPathname;
return h.file(file, { confine: false });
if (!err1) {
return h.file(publicPathname, {
confine: publicRoot
});
}
const filename = manifest[rest];
if (!filename) {
return Boom.notFound();
}
const buildMapPathname = Path.join(buildRoot, filename);
const [err2] = await Intercept(
Fs.access(buildMapPathname, Fs.constants.R_OK)
);
if (!err2) {
return h.file(buildMapPathname, {
confine: buildStatic
});
}
const buildPathname = Path.join(buildStatic, rest);
return h.file(buildPathname, {
confine: buildStatic
});
}
},
{

View File

@ -25,6 +25,7 @@
"apollo-link-http": "^1.5.3",
"apr-intercept": "^3.0.3",
"apr-reduce": "^3.0.3",
"boom": "^7.2.0",
"bytes": "^3.0.0",
"clipboard-copy": "^2.0.0",
"constant-case": "^2.0.0",
@ -34,7 +35,7 @@
"exenv": "^1.2.2",
"fuse.js": "^3.2.0",
"hapi-render-react": "^2.5.2",
"hapi-render-react-joyent-document": "^7.0.1",
"hapi-render-react-joyent-document": "^7.1.0",
"inert": "^5.1.0",
"joyent-logo-assets": "^1.1.0",
"joyent-manifest-editor": "^1.4.0",

View File

@ -1,18 +1,27 @@
const React = require('react');
module.exports = ({ htmlAttrs = {}, bodyAttrs = {}, head = [], children = null }) => (
module.exports = ({
htmlAttrs = {},
bodyAttrs = {},
head = [],
children = null
}) => (
<html {...htmlAttrs}>
<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" />
<meta charSet="utf-8" />
<meta httpEquiv="X-UA-Compatible" content="IE=edge" />
<meta name="theme-color" content="#1E313B" />
<meta
name="viewport"
content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no"
/>
{head}
</head>
<body {...bodyAttrs}>
<div id="header" />
<div id="root" />
{!children ? <div id="root" /> : null}
{children}
<script src="/navigation/static/main.js" />
</body>

View File

@ -7,10 +7,21 @@ const Url = require('url');
const Intercept = require('apr-intercept');
const Fs = require('mz/fs');
const { NAMESPACE = 'navigation' } = process.env;
const { NAMESPACE = 'navigation', NODE_ENV = 'development' } = process.env;
exports.register = async server => {
const manifest = require('../build/asset-manifest.json');
let manifest = {};
try {
manifest = require('../build/asset-manifest.json');
} catch (err) {
if (NODE_ENV === 'production') {
throw err;
} else {
console.error(err);
}
}
const buildRoot = Path.join(__dirname, '../build');
const buildStatic = Path.join(buildRoot, `${NAMESPACE}`);
const publicRoot = Path.join(__dirname, `../public/static`);

View File

@ -1,8 +1,8 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta charSet="utf-8">
<meta httpEquiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<style>

View File

@ -1,6 +1,6 @@
{
"name": "joyent-ui-toolkit",
"version": "6.0.0",
"version": "6.0.1",
"private": true,
"license": "MPL-2.0",
"repository": "github:yldio/joyent-portal",

View File

@ -23,7 +23,6 @@ const Color = styled.div`
margin: ${remcalc(-1)} 0 ${remcalc(-1)} ${remcalc(-1)};
min-width: ${remcalc(12)};
min-height: 100%;
${is('success')`
background-color: ${props => props.theme.green};

View File

@ -15,7 +15,9 @@ module.exports = {
},
pagePerSection: true,
webpackConfig: Object.assign(webpackConfig, {
plugins: webpackConfig.plugins.filter((plugin) => plugin.constructor.name !== 'LodashModuleReplacementPlugin'),
plugins: webpackConfig.plugins.filter(
plugin => plugin.constructor.name !== 'LodashModuleReplacementPlugin'
),
resolve: Object.assign(webpackConfig.resolve, {
alias: Object.assign(webpackConfig.resolve.alias, {
'rsg-components/Wrapper': path.join(__dirname, 'src/styleguide/wrapper')

View File

@ -1,7 +1,7 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta charSet="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<link href='https://fonts.googleapis.com/css?family=Monoton|Pacifico|Roboto+Mono' rel='stylesheet'
type='text/css'>

View File

@ -5205,9 +5205,9 @@ handlebars@^4.0.2, handlebars@^4.0.3:
optionalDependencies:
uglify-js "^2.6"
hapi-render-react-joyent-document@^7.0.1:
version "7.0.1"
resolved "https://registry.yarnpkg.com/hapi-render-react-joyent-document/-/hapi-render-react-joyent-document-7.0.1.tgz#3c7846547f7bcdab668c5d94b748a3d769828ac6"
hapi-render-react-joyent-document@^7.1.0:
version "7.1.0"
resolved "https://registry.yarnpkg.com/hapi-render-react-joyent-document/-/hapi-render-react-joyent-document-7.1.0.tgz#518a8505d31b3fcf65145bb81390402c2cab6ac7"
dependencies:
duplexify "^3.5.4"
pumpify "^1.4.0"