1 |
43335
|
argiro.kok
|
// the polyfills must be the first thing imported in node.js
|
2 |
42781
|
argiro.kok
|
import 'angular2-universal/polyfills';
|
3 |
|
|
|
4 |
|
|
import * as path from 'path';
|
5 |
|
|
import * as express from 'express';
|
6 |
|
|
import * as bodyParser from 'body-parser';
|
7 |
43335
|
argiro.kok
|
import * as cookieParser from 'cookie-parser';
|
8 |
42781
|
argiro.kok
|
|
9 |
43335
|
argiro.kok
|
// Angular 2
|
10 |
|
|
import { enableProdMode } from '@angular/core';
|
11 |
42781
|
argiro.kok
|
// Angular 2 Universal
|
12 |
43335
|
argiro.kok
|
import { expressEngine } from 'angular2-universal';
|
13 |
42781
|
argiro.kok
|
|
14 |
43335
|
argiro.kok
|
// enable prod for faster renders
|
15 |
|
|
enableProdMode();
|
16 |
42781
|
argiro.kok
|
|
17 |
|
|
const app = express();
|
18 |
|
|
const ROOT = path.join(path.resolve(__dirname, '..'));
|
19 |
|
|
|
20 |
|
|
// Express View
|
21 |
|
|
app.engine('.html', expressEngine);
|
22 |
|
|
app.set('views', __dirname);
|
23 |
|
|
app.set('view engine', 'html');
|
24 |
|
|
|
25 |
43335
|
argiro.kok
|
app.use(cookieParser('Angular 2 Universal'));
|
26 |
42781
|
argiro.kok
|
app.use(bodyParser.json());
|
27 |
|
|
|
28 |
43335
|
argiro.kok
|
// Serve static files
|
29 |
|
|
app.use('/assets', express.static(path.join(__dirname, 'assets'), {maxAge: 30}));
|
30 |
|
|
app.use(express.static(path.join(ROOT, 'dist/client'), {index: false}));
|
31 |
43497
|
argiro.kok
|
/* **AK** Add this path so that index.html can see files from node_modules folder (e.g. bootstrap files)*/
|
32 |
|
|
app.use(express.static(path.join(ROOT, 'node_modules'), {index: false}));
|
33 |
42781
|
argiro.kok
|
|
34 |
|
|
|
35 |
43497
|
argiro.kok
|
|
36 |
43335
|
argiro.kok
|
// import { serverApi } from './backend/api';
|
37 |
|
|
// // Our API for demos only
|
38 |
|
|
// app.get('/data.json', serverApi);
|
39 |
42781
|
argiro.kok
|
|
40 |
43335
|
argiro.kok
|
import { ngApp } from './main.node';
|
41 |
|
|
// Routes with html5pushstate
|
42 |
|
|
// ensure routes match client-side-app
|
43 |
|
|
app.get('/', ngApp);
|
44 |
|
|
app.get('/claims', ngApp);
|
45 |
|
|
app.get('/claim', ngApp);
|
46 |
|
|
app.get('/home', ngApp);
|
47 |
|
|
app.get('/search', ngApp);
|
48 |
|
|
app.get('/search-publications', ngApp);
|
49 |
|
|
app.get('/my-claims', ngApp);
|
50 |
|
|
app.get('/linking', ngApp);
|
51 |
|
|
app.get('/demo-up', ngApp);
|
52 |
|
|
app.get('/up', ngApp);
|
53 |
43398
|
argiro.kok
|
app.get('/bulk-linking', ngApp);
|
54 |
43488
|
argiro.kok
|
app.get('/publication', ngApp);
|
55 |
|
|
app.get('/project', ngApp);
|
56 |
43490
|
argiro.kok
|
app.get('/person', ngApp);
|
57 |
|
|
app.get('/dataset', ngApp);
|
58 |
43494
|
konstantin
|
app.get('/organization', ngApp);
|
59 |
43495
|
argiro.kok
|
app.get('/deposit', ngApp);
|
60 |
42781
|
argiro.kok
|
|
61 |
43335
|
argiro.kok
|
// use indexFile over ngApp only when there is too much load on the server
|
62 |
42781
|
argiro.kok
|
function indexFile(req, res) {
|
63 |
43335
|
argiro.kok
|
// when there is too much load on the server just send
|
64 |
|
|
// the index.html without prerendering for client-only
|
65 |
42781
|
argiro.kok
|
res.sendFile('/index.html', {root: __dirname});
|
66 |
|
|
}
|
67 |
|
|
|
68 |
43335
|
argiro.kok
|
app.get('*', function(req, res) {
|
69 |
|
|
res.setHeader('Content-Type', 'application/json');
|
70 |
|
|
var pojo = { status: 404, message: 'No Content' };
|
71 |
|
|
var json = JSON.stringify(pojo, null, 2);
|
72 |
|
|
res.status(404).send(json);
|
73 |
42781
|
argiro.kok
|
});
|
74 |
|
|
|
75 |
|
|
// Server
|
76 |
43229
|
argiro.kok
|
app.listen(3000, () => {
|
77 |
|
|
console.log('Listening on: http://localhost:3000');
|
78 |
42781
|
argiro.kok
|
});
|