Using a single index file. Updated servers. Removed duplicate npm scripts.

This commit is contained in:
William Welling
2017-03-22 08:05:27 -05:00
parent 9dd08c8597
commit 9496bf7e42
7 changed files with 71 additions and 78 deletions

2
.gitignore vendored
View File

@@ -26,4 +26,6 @@ webpack.records.json
morgan.log morgan.log
yarn-error.log
*.css *.css

View File

@@ -35,20 +35,12 @@
"build:prod:json:rollup": "yarn run build:prod:json && yarn run rollup", "build:prod:json:rollup": "yarn run build:prod:json && yarn run rollup",
"ngc": "ngc -p tsconfig.aot.json", "ngc": "ngc -p tsconfig.aot.json",
"prestart": "yarn run build:prod:ngc:json", "prestart": "yarn run build:prod:ngc:json",
"server": "node dist/server/build.js", "server": "node dist/server/index.js",
"server:dev": "node dist/server/index.js", "server:dev": "node dist/server/index.js",
"server:dev:watch": "nodemon --debug dist/server/index.js", "server:dev:watch": "nodemon --debug dist/server/index.js",
"start": "yarn run server", "start": "yarn run server",
"start:dev": "yarn run clean:prod && yarn run build && yarn run server:dev", "start:dev": "yarn run clean:prod && yarn run build && yarn run server:dev",
"watch": "webpack -w & yarn run style:watch", "watch": "webpack -w & yarn run style:watch",
"watch:dev:server": "concurrently \"yarn run server:dev:watch\" \"yarn run watch\"",
"watch:dev": "yarn run clean:prod && yarn run build && yarn run watch:dev:server",
"watch:prod:server": "concurrently \"yarn run server\" \"yarn run watch\"",
"watch:prod": "yarn run build:prod:ngc:json && yarn run watch:prod:server",
"predebug": "yarn run build",
"start": "yarn run server",
"start:dev": "yarn run clean:prod && yarn run build && yarn run server:dev",
"watch": "webpack -w & yarn run style:watch",
"watch:dev:server": "npm-run-all -p server:dev:watch watch", "watch:dev:server": "npm-run-all -p server:dev:watch watch",
"watch:dev": "yarn run clean:prod && yarn run build && yarn run watch:dev:server", "watch:dev": "yarn run clean:prod && yarn run build && yarn run watch:dev:server",
"watch:prod:server": "npm-run-all -p server watch", "watch:prod:server": "npm-run-all -p server watch",

View File

@@ -4,15 +4,13 @@ import commonjs from 'rollup-plugin-commonjs';
import uglify from 'rollup-plugin-uglify' import uglify from 'rollup-plugin-uglify'
export default { export default {
entry: 'dist/client/main.bundle.js', entry : 'dist/client/main.bundle.js',
dest: 'dist/client/build.js', dest : 'dist/client/main.bundle.js',
sourceMap: false, sourceMap : false,
format: 'iife', format : 'iife',
plugins: [ plugins : [
nodeResolve({jsnext: true, module: true}), nodeResolve({jsnext: true, module: true}),
commonjs({ commonjs({include: 'node_modules/rxjs/**'}),
include: 'node_modules/rxjs/**',
}),
uglify() uglify()
] ]
} }

View File

@@ -4,15 +4,13 @@ import commonjs from 'rollup-plugin-commonjs';
import uglify from 'rollup-plugin-uglify' import uglify from 'rollup-plugin-uglify'
export default { export default {
entry: 'dist/server/index.js', entry : 'dist/server/index.js',
dest: 'dist/server/build.js', dest : 'dist/server/index.js',
sourceMap: false, sourceMap : false,
format: 'iife', format : 'iife',
plugins: [ plugins : [
nodeResolve({jsnext: true, module: true}), nodeResolve({jsnext: true, module: true}),
commonjs({ commonjs({include: 'node_modules/rxjs/**'}),
include: 'node_modules/rxjs/**',
}),
uglify() uglify()
] ]
} }

View File

@@ -1,20 +0,0 @@
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>DSpace</title>
<meta name="viewport" content="width=device-width,minimum-scale=1">
<link rel="icon" href="data:;base64,iVBORw0KGgo=">
<link rel="stylesheet" href="/styles/main.css">
<base href="/">
</head>
<body>
<ds-app>
Loading DSpace ...
</ds-app>
<script async src="/build.js"></script>
</body>
</html>

View File

@@ -43,11 +43,12 @@ app.engine('.html', createEngine({
] ]
})); }));
app.set('port', process.env.PORT || 3000); app.set('port', process.env.PORT || 3000);
app.set('address', process.env.ADDRESS || '127.0.0.1');
app.set('views', __dirname); app.set('views', __dirname);
app.set('view engine', 'html'); app.set('view engine', 'html');
app.set('json spaces', 2); app.set('json spaces', 2);
app.use(cookieParser('Angular 2 Universal')); app.use(cookieParser('DSpace Universal'));
app.use(bodyParser.json()); app.use(bodyParser.json());
app.use(compression()); app.use(compression());
@@ -79,16 +80,27 @@ app.get('/data.json', serverApi);
app.use('/api', createMockApi()); app.use('/api', createMockApi());
function ngApp(req, res) { function ngApp(req, res) {
res.render('index-aot', {
function onHandleError(parentZoneDelegate, currentZone, targetZone, error) {
console.warn('Error in SSR, serving for direct CSR', error);
res.sendFile('index.html', { root: './src' });
return false;
}
Zone.current.fork({ name: 'CSR fallback', onHandleError }).run(() => {
res.render('index', {
req, req,
res, res,
// time: true, // use this to determine what part of your app is slow only in development // use this to determine what part of your app is slow only in development
// time: true,
async: true, async: true,
preboot: true, preboot: true,
baseUrl: '/', baseUrl: '/',
requestUrl: req.originalUrl, requestUrl: req.originalUrl,
originUrl: `http://localhost:${app.get('port')}` originUrl: `http://${app.get('address')}:${app.get('port')}`
}); });
});
} }
/** /**
@@ -110,5 +122,5 @@ app.get('*', function(req, res) {
// Server // Server
let server = app.listen(app.get('port'), () => { let server = app.listen(app.get('port'), () => {
console.log(`Listening on: http://localhost:${server.address().port}`); console.log(`Listening on: http://${server.address().address}:${server.address().port}`);
}); });

View File

@@ -41,6 +41,7 @@ app.engine('.html', createEngine({
] ]
})); }));
app.set('port', process.env.PORT || 3000); app.set('port', process.env.PORT || 3000);
app.set('address', process.env.ADDRESS || '127.0.0.1');
app.set('views', __dirname); app.set('views', __dirname);
app.set('view engine', 'html'); app.set('view engine', 'html');
app.set('json spaces', 2); app.set('json spaces', 2);
@@ -72,6 +73,14 @@ app.get('/data.json', serverApi);
app.use('/api', createMockApi()); app.use('/api', createMockApi());
function ngApp(req, res) { function ngApp(req, res) {
function onHandleError(parentZoneDelegate, currentZone, targetZone, error) {
console.warn('Error in SSR, serving for direct CSR');
res.sendFile('index.html', { root: './src' });
return false;
}
Zone.current.fork({ name: 'CSR fallback', onHandleError }).run(() => {
res.render('index', { res.render('index', {
req, req,
res, res,
@@ -80,8 +89,10 @@ function ngApp(req, res) {
preboot: true, preboot: true,
baseUrl: '/', baseUrl: '/',
requestUrl: req.originalUrl, requestUrl: req.originalUrl,
originUrl: `http://localhost:${app.get('port')}` originUrl: `http://${app.get('address')}:${app.get('port')}`
}); });
});
} }
/** /**
@@ -102,5 +113,5 @@ app.get('*', function(req, res) {
// Server // Server
let server = app.listen(app.get('port'), () => { let server = app.listen(app.get('port'), () => {
console.log(`Listening on: http://localhost:${server.address().port}`); console.log(`Listening on: http://${server.address().address}:${server.address().port}`);
}); });