80 lines
2.4 KiB
TypeScript
80 lines
2.4 KiB
TypeScript
// the polyfills must be the first thing imported in node.js
|
|
import 'angular2-universal/polyfills';
|
|
|
|
import * as path from 'path';
|
|
import * as express from 'express';
|
|
import * as bodyParser from 'body-parser';
|
|
import * as cookieParser from 'cookie-parser';
|
|
|
|
// Angular 2
|
|
import { enableProdMode } from '@angular/core';
|
|
// Angular 2 Universal
|
|
import { expressEngine } from 'angular2-universal';
|
|
|
|
// enable prod for faster renders
|
|
enableProdMode();
|
|
|
|
const app = express();
|
|
const ROOT = path.join(path.resolve(__dirname, '..'));
|
|
|
|
// Express View
|
|
app.engine('.html', expressEngine);
|
|
app.set('views', __dirname);
|
|
app.set('view engine', 'html');
|
|
|
|
app.use(cookieParser('Angular 2 Universal'));
|
|
app.use(bodyParser.json());
|
|
|
|
// Serve static files
|
|
app.use('/assets', express.static(path.join(__dirname, 'assets'), {maxAge: 30}));
|
|
app.use(express.static(path.join(ROOT, 'dist/client'), {index: false}));
|
|
/* **AK** Add this path so that index.html can see files from node_modules folder (e.g. bootstrap files)*/
|
|
app.use(express.static(path.join(ROOT, 'node_modules'), {index: false}));
|
|
|
|
|
|
|
|
// import { serverApi } from './backend/api';
|
|
// // Our API for demos only
|
|
// app.get('/data.json', serverApi);
|
|
|
|
import { ngApp } from './main.node';
|
|
// Routes with html5pushstate
|
|
// ensure routes match client-side-app
|
|
app.get('/', ngApp);
|
|
app.get('/claims', ngApp);
|
|
app.get('/claim', ngApp);
|
|
app.get('/home', ngApp);
|
|
app.get('/search', ngApp);
|
|
app.get('/search-publications', ngApp);
|
|
app.get('/advanced-search-publications', ngApp);
|
|
app.get('/my-claims', ngApp);
|
|
app.get('/linking', ngApp);
|
|
app.get('/demo-up', ngApp);
|
|
app.get('/up', ngApp);
|
|
app.get('/bulk-linking', ngApp);
|
|
app.get('/publication', ngApp);
|
|
app.get('/project', ngApp);
|
|
app.get('/person', ngApp);
|
|
app.get('/dataset', ngApp);
|
|
app.get('/organization', ngApp);
|
|
app.get('/deposit', ngApp);
|
|
|
|
// use indexFile over ngApp only when there is too much load on the server
|
|
function indexFile(req, res) {
|
|
// when there is too much load on the server just send
|
|
// the index.html without prerendering for client-only
|
|
res.sendFile('/index.html', {root: __dirname});
|
|
}
|
|
|
|
app.get('*', function(req, res) {
|
|
res.setHeader('Content-Type', 'application/json');
|
|
var pojo = { status: 404, message: 'No Content' };
|
|
var json = JSON.stringify(pojo, null, 2);
|
|
res.status(404).send(json);
|
|
});
|
|
|
|
// Server
|
|
app.listen(3000, () => {
|
|
console.log('Listening on: http://localhost:3000');
|
|
});
|