// 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 { createEngine } from 'angular2-express-engine'; // App import { MainModule } from './app.node.module'; // enable prod for faster renders enableProdMode(); const app = express(); const ROOT = path.join(path.resolve(__dirname, '..')); // Express View app.engine('.html', createEngine({})); 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})); // app.get('/bootstrap.css', express.static(path.join(ROOT, 'node_modules/bootstrap/dist/css/bootstrap.min.css'))); import { serverApi } from './backend/api'; // Our API for demos only app.get('/data.json', serverApi); function ngApp(req, res) { res.render('index', { req, res, ngModule: MainModule, preboot: false, baseUrl: '/', requestUrl: req.originalUrl, originUrl: 'http://localhost:3000' }); } // Routes with html5pushstate // ensure routes match client-side-app app.get('/', ngApp); app.get('/claims', ngApp); app.get('/home', ngApp); app.get('/claim', ngApp); app.get('/myclaims', ngApp); app.get('/linking', ngApp); app.get('/bulk-linking', ngApp); app.get('/search/person', ngApp); app.get('/search/project', ngApp); app.get('/search/organization', ngApp); app.get('/search/dataset', ngApp); app.get('/search/dataprovider', ngApp); app.get('search/data-providers', ngApp); app.get('search/entity-registries', ngApp); app.get('/search/publication', ngApp); app.get('/search', ngApp); app.get('/search/find/publications', ngApp); app.get('/search/advanced/publications', ngApp); app.get('/search/advanced/dataproviders', ngApp); app.get('/search/advanced/projects', ngApp); app.get('/search/find/dataproviders', ngApp); app.get('/search/find/projects', ngApp); app.get('/search/find/datasets', ngApp); app.get('/search/find/organizations', ngApp); app.get('/search/find/people', ngApp); app.get('/deposit', ngApp); app.get('/deposit-result', ngApp); app.get('/error', ngApp); app.get('/test', ngApp); app.get('/refineResults.json', function(req, res) { res.setHeader('Content-Type', 'application/json'); var pojo = { "refineResults":[ { "projectendyear":[ { "name":"2016", "id":"2016", "count":"103" }, { "name":"2015", "id":"2015", "count":"91" }, { "name":"2013", "id":"2013", "count":"69" }, { "name":"2010", "id":"2010", "count":"60" }, { "name":"2011", "id":"2011", "count":"59" }, { "name":"2014", "id":"2014", "count":"59" }, { "name":"2012", "id":"2012", "count":"58" }, { "name":"2005", "id":"2005", "count":"54" }, { "name":"2000", "id":"2000", "count":"52" }, { "name":"2006", "id":"2006", "count":"51" }, { "name":"2007", "id":"2007", "count":"51" }, { "name":"2017", "id":"2017", "count":"49" }, { "name":"2009", "id":"2009", "count":"48" }, { "name":"2002", "id":"2002", "count":"43" }, { "name":"2004", "id":"2004", "count":"43" }, { "name":"2001", "id":"2001", "count":"41" }, { "name":"1999", "id":"1999", "count":"40" }, { "name":"2008", "id":"2008", "count":"37" }, { "name":"1997", "id":"1997", "count":"35" }, { "name":"2003", "id":"2003", "count":"35" }, { "name":"1998", "id":"1998", "count":"33" }, { "name":"1993", "id":"1993", "count":"28" }, { "name":"1995", "id":"1995", "count":"28" }, { "name":"1990", "id":"1990", "count":"27" }, { "name":"1994", "id":"1994", "count":"24" }, { "name":"1996", "id":"1996", "count":"23" }, { "name":"1992", "id":"1992", "count":"22" }, { "name":"1979", "id":"1979", "count":"19" }, { "name":"1988", "id":"1988", "count":"19" }, { "name":"1989", "id":"1989", "count":"18" }, { "name":"1991", "id":"1991", "count":"18" }, { "name":"1974", "id":"1974", "count":"17" }, { "name":"2018", "id":"2018", "count":"17" }, { "name":"1975", "id":"1975", "count":"14" }, { "name":"1986", "id":"1986", "count":"14" }, { "name":"1982", "id":"1982", "count":"13" }, { "name":"1987", "id":"1987", "count":"13" }, { "name":"1981", "id":"1981", "count":"12" }, { "name":"1985", "id":"1985", "count":"12" }, { "name":"1976", "id":"1976", "count":"11" }, { "name":"1983", "id":"1983", "count":"9" }, { "name":"2019", "id":"2019", "count":"9" }, { "name":"1973", "id":"1973", "count":"8" }, { "name":"1980", "id":"1980", "count":"8" }, { "name":"1968", "id":"1968", "count":"7" }, { "name":"1984", "id":"1984", "count":"7" }, { "name":"1970", "id":"1970", "count":"6" }, { "name":"1969", "id":"1969", "count":"5" }, { "name":"1978", "id":"1978", "count":"5" }, { "name":"2020", "id":"2020", "count":"5" }, { "name":"1966", "id":"1966", "count":"3" }, { "name":"1972", "id":"1972", "count":"3" }, { "name":"1977", "id":"1977", "count":"3" }, { "name":"1962", "id":"1962", "count":"2" }, { "name":"1963", "id":"1963", "count":"2" }, { "name":"1971", "id":"1971", "count":"2" }, { "name":"1960", "id":"1960", "count":"1" }, { "name":"1961", "id":"1961", "count":"1" }, { "name":"1964", "id":"1964", "count":"1" }, { "name":"1967", "id":"1967", "count":"1" }, { "name":"2021", "id":"2021", "count":"1" } ] }, { "projectstartyear":[ { "name":"2015", "id":"2015", "count":"75" }, { "name":"2008", "id":"2008", "count":"71" }, { "name":"2011", "id":"2011", "count":"66" }, { "name":"2009", "id":"2009", "count":"65" }, { "name":"2010", "id":"2010", "count":"65" }, { "name":"2003", "id":"2003", "count":"63" }, { "name":"2013", "id":"2013", "count":"62" }, { "name":"2012", "id":"2012", "count":"61" }, { "name":"2014", "id":"2014", "count":"61" }, { "name":"2005", "id":"2005", "count":"59" }, { "name":"2002", "id":"2002", "count":"54" }, { "name":"2004", "id":"2004", "count":"50" }, { "name":"2007", "id":"2007", "count":"49" }, { "name":"2006", "id":"2006", "count":"47" }, { "name":"1996", "id":"1996", "count":"45" }, { "name":"1997", "id":"1997", "count":"44" }, { "name":"1998", "id":"1998", "count":"44" }, { "name":"2001", "id":"2001", "count":"40" }, { "name":"2000", "id":"2000", "count":"38" }, { "name":"1999", "id":"1999", "count":"36" }, { "name":"1992", "id":"1992", "count":"34" }, { "name":"1991", "id":"1991", "count":"32" }, { "name":"1974", "id":"1974", "count":"31" }, { "name":"1994", "id":"1994", "count":"31" }, { "name":"1993", "id":"1993", "count":"30" }, { "name":"1990", "id":"1990", "count":"27" }, { "name":"1995", "id":"1995", "count":"27" }, { "name":"1987", "id":"1987", "count":"24" }, { "name":"1985", "id":"1985", "count":"23" }, { "name":"1988", "id":"1988", "count":"18" }, { "name":"2016", "id":"2016", "count":"18" }, { "name":"1989", "id":"1989", "count":"17" }, { "name":"1976", "id":"1976", "count":"16" }, { "name":"1986", "id":"1986", "count":"16" }, { "name":"1977", "id":"1977", "count":"14" }, { "name":"1980", "id":"1980", "count":"13" }, { "name":"1981", "id":"1981", "count":"12" }, { "name":"1983", "id":"1983", "count":"12" }, { "name":"1973", "id":"1973", "count":"10" }, { "name":"1968", "id":"1968", "count":"9" }, { "name":"1978", "id":"1978", "count":"8" }, { "name":"1979", "id":"1979", "count":"8" }, { "name":"1984", "id":"1984", "count":"8" }, { "name":"1972", "id":"1972", "count":"6" }, { "name":"1982", "id":"1982", "count":"6" }, { "name":"1967", "id":"1967", "count":"4" }, { "name":"1969", "id":"1969", "count":"4" }, { "name":"1961", "id":"1961", "count":"3" }, { "name":"1965", "id":"1965", "count":"3" }, { "name":"1970", "id":"1970", "count":"3" }, { "name":"1971", "id":"1971", "count":"3" }, { "name":"1975", "id":"1975", "count":"3" }, { "name":"1962", "id":"1962", "count":"2" }, { "name":"1917", "id":"1917", "count":"1" }, { "name":"1959", "id":"1959", "count":"1" }, { "name":"1960", "id":"1960", "count":"1" }, { "name":"1963", "id":"1963", "count":"1" }, { "name":"1966", "id":"1966", "count":"1" } ] }, { "funderid":[ { "name":"nsf_________::NSF", "id":"nsf_________::NSF", "count":"1060" }, { "name":"ec__________::EC", "id":"ec__________::EC", "count":"150" }, { "name":"nhmrc_______::NHMRC", "id":"nhmrc_______::NHMRC", "count":"90" }, { "name":"arc_________::ARC", "id":"arc_________::ARC", "count":"62" }, { "name":"fct_________::FCT", "id":"fct_________::FCT", "count":"50" }, { "name":"wt__________::WT", "id":"wt__________::WT", "count":"21" }, { "name":"sfi_________::SFI", "id":"sfi_________::SFI", "count":"17" }, { "name":"irb_hr______::MSES", "id":"irb_hr______::MSES", "count":"1" } ] }, { "projectecsc39":[ { "name":"false", "id":"false", "count":"96" }, { "name":"true", "id":"true", "count":"4" } ] } ] }; var json = JSON.stringify(pojo, null, 2); res.status(200).send(json); }); app.get('*', ngApp); // Server let server = app.listen(process.env.PORT || 3000, () => { console.log(`Listening on: http://localhost:${server.address().port}`); });