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
yarn-error.log
*.css

View File

@@ -35,20 +35,12 @@
"build:prod:json:rollup": "yarn run build:prod:json && yarn run rollup",
"ngc": "ngc -p tsconfig.aot.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:watch": "nodemon --debug dist/server/index.js",
"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": "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": "yarn run clean:prod && yarn run build && yarn run watch:dev:server",
"watch:prod:server": "npm-run-all -p server watch",

View File

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

View File

@@ -1,18 +1,16 @@
import rollup from 'rollup'
import rollup from 'rollup'
import nodeResolve from 'rollup-plugin-node-resolve'
import commonjs from 'rollup-plugin-commonjs';
import uglify from 'rollup-plugin-uglify'
import commonjs from 'rollup-plugin-commonjs';
import uglify from 'rollup-plugin-uglify'
export default {
entry: 'dist/server/index.js',
dest: 'dist/server/build.js',
sourceMap: false,
format: 'iife',
plugins: [
nodeResolve({jsnext: true, module: true}),
commonjs({
include: 'node_modules/rxjs/**',
}),
uglify()
]
entry : 'dist/server/index.js',
dest : 'dist/server/index.js',
sourceMap : false,
format : 'iife',
plugins : [
nodeResolve({jsnext: true, module: true}),
commonjs({include: 'node_modules/rxjs/**'}),
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('address', process.env.ADDRESS || '127.0.0.1');
app.set('views', __dirname);
app.set('view engine', 'html');
app.set('json spaces', 2);
app.use(cookieParser('Angular 2 Universal'));
app.use(cookieParser('DSpace Universal'));
app.use(bodyParser.json());
app.use(compression());
@@ -79,16 +80,27 @@ app.get('/data.json', serverApi);
app.use('/api', createMockApi());
function ngApp(req, res) {
res.render('index-aot', {
req,
res,
// time: true, // use this to determine what part of your app is slow only in development
async: true,
preboot: true,
baseUrl: '/',
requestUrl: req.originalUrl,
originUrl: `http://localhost:${app.get('port')}`
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,
res,
// use this to determine what part of your app is slow only in development
// time: true,
async: true,
preboot: true,
baseUrl: '/',
requestUrl: req.originalUrl,
originUrl: `http://${app.get('address')}:${app.get('port')}`
});
});
}
/**
@@ -110,5 +122,5 @@ app.get('*', function(req, res) {
// Server
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('address', process.env.ADDRESS || '127.0.0.1');
app.set('views', __dirname);
app.set('view engine', 'html');
app.set('json spaces', 2);
@@ -72,16 +73,26 @@ app.get('/data.json', serverApi);
app.use('/api', createMockApi());
function ngApp(req, res) {
res.render('index', {
req,
res,
// time: true, // use this to determine what part of your app is slow only in development
async: true,
preboot: true,
baseUrl: '/',
requestUrl: req.originalUrl,
originUrl: `http://localhost:${app.get('port')}`
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', {
req,
res,
// time: true, // use this to determine what part of your app is slow only in development
async: true,
preboot: true,
baseUrl: '/',
requestUrl: req.originalUrl,
originUrl: `http://${app.get('address')}:${app.get('port')}`
});
});
}
/**
@@ -102,5 +113,5 @@ app.get('*', function(req, res) {
// Server
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}`);
});