Compare commits

..

4 Commits

7 changed files with 66 additions and 105 deletions

View File

@ -203,18 +203,18 @@
"serve": { "serve": {
"builder": "@angular-devkit/build-angular:dev-server", "builder": "@angular-devkit/build-angular:dev-server",
"options": { "options": {
"browserTarget": "aggregator:build" "buildTarget": "aggregator:build"
}, },
"configurations": { "configurations": {
"production": { "production": {
"browserTarget": "aggregator:build:production" "buildTarget": "aggregator:build:production"
} }
} }
}, },
"extract-i18n": { "extract-i18n": {
"builder": "@angular-devkit/build-angular:extract-i18n", "builder": "@angular-devkit/build-angular:extract-i18n",
"options": { "options": {
"browserTarget": "aggregator:build" "buildTarget": "aggregator:build"
} }
}, },
"test": { "test": {
@ -287,7 +287,7 @@
"defaultConfiguration": "" "defaultConfiguration": ""
}, },
"serve-ssr": { "serve-ssr": {
"builder": "@nguniversal/builders:ssr-dev-server", "builder": "@angular-devkit/build-angular:ssr-dev-server",
"options": { "options": {
"browserTarget": "aggregator:build", "browserTarget": "aggregator:build",
"serverTarget": "aggregator:server" "serverTarget": "aggregator:server"
@ -300,7 +300,7 @@
} }
}, },
"prerender": { "prerender": {
"builder": "@nguniversal/builders:prerender", "builder": "@angular-devkit/build-angular:prerender",
"options": { "options": {
"browserTarget": "aggregator:build:production", "browserTarget": "aggregator:build:production",
"serverTarget": "aggregator:server:production", "serverTarget": "aggregator:server:production",

View File

@ -21,42 +21,42 @@
}, },
"private": true, "private": true,
"dependencies": { "dependencies": {
"@angular/animations": "^16.1.8", "@angular/animations": "^17.3.11",
"@angular/cdk": "^16.1.7", "@angular/cdk": "^17.3.10",
"@angular/common": "^16.1.8", "@angular/common": "^17.3.11",
"@angular/compiler": "^16.1.8", "@angular/compiler": "^17.3.11",
"@angular/core": "^16.1.8", "@angular/core": "^17.3.11",
"@angular/forms": "^16.1.8", "@angular/forms": "^17.3.11",
"@angular/localize": "^16.1.8", "@angular/localize": "^17.3.11",
"@angular/material": "^16.1.7", "@angular/material": "^17.3.10",
"@angular/platform-browser": "^16.1.8", "@angular/platform-browser": "^17.3.11",
"@angular/platform-browser-dynamic": "^16.1.8", "@angular/platform-browser-dynamic": "^17.3.11",
"@angular/platform-server": "^16.1.8", "@angular/platform-server": "^17.3.11",
"@angular/router": "^16.1.8", "@angular/router": "^17.3.11",
"@nguniversal/express-engine": "^16.1.1", "@angular/ssr": "^17.3.8",
"clipboard": "^1.5.16", "clipboard": "^1.5.16",
"core-js": "^2.5.4", "core-js": "^2.5.4",
"express": "^4.15.2", "express": "^4.15.2",
"jquery": "^3.4.1", "jquery": "^3.4.1",
"ng-recaptcha": "^12.0.2", "ng-recaptcha": "^13.2.1",
"prom-client": "^11.3.0", "prom-client": "^11.3.0",
"rxjs": "^6.5.1", "rxjs": "^6.5.1",
"ts-md5": "^1.2.0", "ts-md5": "^1.2.0",
"tslib": "^2.0.0", "tslib": "^2.0.0",
"uikit": "3.16.24", "uikit": "3.16.24",
"zone.js": "~0.13.1" "zone.js": "~0.14.0"
}, },
"devDependencies": { "devDependencies": {
"@angular-devkit/build-angular": "^16.1.7", "@angular-devkit/build-angular": "^17.3.8",
"@angular/cli": "^16.1.7", "@angular/cli": "^17.3.8",
"@angular/compiler-cli": "^16.1.8", "@angular/compiler-cli": "^17.3.11",
"@angular/language-service": "^16.1.8", "@angular/language-service": "^17.3.11",
"@nguniversal/builders": "^16.1.1",
"@types/express": "^4.17.0",
"@types/compression": "^1.7.0", "@types/compression": "^1.7.0",
"@types/node": "^16.18.50", "@types/express": "^4.17.0",
"@types/jasmine": "~3.6.0", "@types/jasmine": "~3.6.0",
"@types/jasminewd2": "~2.0.3", "@types/jasminewd2": "~2.0.3",
"@types/node": "^16.18.50",
"browser-sync": "^3.0.0",
"codelyzer": "^6.0.0", "codelyzer": "^6.0.0",
"jasmine-core": "~3.8.0", "jasmine-core": "~3.8.0",
"jasmine-spec-reporter": "~5.0.0", "jasmine-spec-reporter": "~5.0.0",
@ -67,6 +67,6 @@
"karma-jasmine-html-reporter": "^1.6.0", "karma-jasmine-html-reporter": "^1.6.0",
"protractor": "~7.0.0", "protractor": "~7.0.0",
"ts-node": "~7.0.0", "ts-node": "~7.0.0",
"typescript": "~4.9.5" "typescript": "~5.2.0"
} }
} }

101
server.ts
View File

@ -1,31 +1,22 @@
import 'zone.js/node'; import 'zone.js/node';
import { ngExpressEngine } from '@nguniversal/express-engine';
import * as express from 'express';
import * as compression from 'compression';
import { join } from 'path';
import { AppServerModule } from './src/main.server';
import { APP_BASE_HREF } from '@angular/common'; import { APP_BASE_HREF } from '@angular/common';
import { existsSync } from 'fs'; import { CommonEngine } from '@angular/ssr';
import {Prometheus} from "./prometheus"; import * as express from 'express';
import {Counter} from "prom-client"; import { existsSync } from 'node:fs';
import {REQUEST, RESPONSE} from "./src/app/openaireLibrary/utils/tokens"; import { join } from 'node:path';
import bootstrap from './src/main.server';
// The Express app is exported so that it can be used by serverless Functions. // The Express app is exported so that it can be used by serverless Functions.
export function app() { export function app(): express.Express {
const server = express(); const server = express();
server.use(compression());
const distFolder = join(process.cwd(), 'dist/aggregator/browser'); const distFolder = join(process.cwd(), 'dist/aggregator/browser');
const indexHtml = existsSync(join(distFolder, 'index.original.html')) ? 'index.original.html' : 'index'; const indexHtml = existsSync(join(distFolder, 'index.original.html'))
? join(distFolder, 'index.original.html')
const prometheus: Prometheus = new Prometheus(); : join(distFolder, 'index.html');
// Our Universal express-engine (found @ https://github.com/angular/universal/tree/master/modules/express-engine) const commonEngine = new CommonEngine();
server.engine('html', ngExpressEngine({
bootstrap: AppServerModule,
inlineCriticalCss: false
}));
server.set('view engine', 'html'); server.set('view engine', 'html');
server.set('views', distFolder); server.set('views', distFolder);
@ -36,59 +27,29 @@ export function app() {
server.get('*.*', express.static(distFolder, { server.get('*.*', express.static(distFolder, {
maxAge: '1y' maxAge: '1y'
})); }));
server.get('/metrics', (req, res) => { // All regular routes use the Angular engine
res.set('Content-Type', prometheus.register.contentType); server.get('*', (req, res, next) => {
res.end(prometheus.register.metrics()); const { protocol, originalUrl, baseUrl, headers } = req;
});
commonEngine
// All regular routes use the Universal engine .render({
server.get('*', (req, res) => { bootstrap,
let start = new Date(); documentFilePath: indexHtml,
let counter: Counter = prometheus.counters.get(req.path); url: `${protocol}://${headers.host}${originalUrl}`,
if(counter !== undefined) { publicPath: distFolder,
counter.inc(1, new Date()); providers: [
res.render(indexHtml, { { provide: APP_BASE_HREF, useValue: baseUrl },],
req, providers: [ })
{ .then((html) => res.send(html))
provide: APP_BASE_HREF, .catch((err) => next(err));
useValue: req.baseUrl
},
{
provide: REQUEST, useValue: (req)
},
{
provide: RESPONSE, useValue: (res)
}
]
});
// event triggers when express is done sending response
res.on('finish', function() {
console.log(new Date().getTime() - start.getTime());
});
} else {
res.render(indexHtml, {
req, providers: [
{
provide: APP_BASE_HREF,
useValue: req.baseUrl
},
{
provide: REQUEST, useValue: (req)
},
{
provide: RESPONSE, useValue: (res)
}
]
});
}
}); });
return server; return server;
} }
function run() { function run(): void {
const port = process.env.PORT || 4000; const port = process.env['PORT'] || 4000;
// Start up the Node server // Start up the Node server
const server = app(); const server = app();
@ -107,4 +68,4 @@ if (moduleFilename === __filename || moduleFilename.includes('iisnode')) {
run(); run();
} }
export * from './src/main.server'; export default bootstrap;

View File

@ -25,12 +25,12 @@ import {OpenaireEntities} from "../openaireLibrary/utils/properties/searchFields
</div> </div>
<h3>For {{openaireEntities.RESULTS | lowercase}}</h3> <h3>For {{openaireEntities.RESULTS | lowercase}}</h3>
<div class="uk-margin-bottom"> <div class="uk-margin-bottom">
For {{openaireEntities.RESULTS | lowercase}} ({{openaireEntities.PUBLICATIONS | lowercase}}, {{openaireEntities.DATASETS | lowercase}}, {{openaireEntities.SOFTWARE | lowercase}} and {{openaireEntities.OTHER | lowercase}}) you can use the Graph API by adding the community parameter. For {{openaireEntities.RESULTS | lowercase}} ({{openaireEntities.PUBLICATIONS | lowercase}}, {{openaireEntities.DATASETS | lowercase}}, {{openaireEntities.SOFTWARE | lowercase}} and {{openaireEntities.OTHER | lowercase}}) you can use the Selective Access APIs by adding the community parameter.
</div> </div>
<a class="uk-display-inline-block uk-button uk-button-text" <a class="uk-display-inline-block uk-button uk-button-text"
href="https://graph.openaire.eu/docs/apis/search-api/research-products" target="_blank"> href="https://graph.openaire.eu/develop/api.html" target="_blank">
<span class="uk-flex uk-flex-middle"> <span class="uk-flex uk-flex-middle">
<span>Graph API</span> <span>Selective Access APIs</span>
</span> </span>
</a> </a>
</div> </div>

@ -1 +1 @@
Subproject commit fe09fbfdcb6087e1f7e8373b654a29214adab65d Subproject commit 5f691d18c4ed14f23c35cbdb9746d9d5cd71b221

@ -1 +1 @@
Subproject commit 014adfe4588975e499c72b284ce7368fc2cb5d14 Subproject commit ee1a55a529fde844f54761633e59f3be791717e3

@ -1 +1 @@
Subproject commit 55765bf0829910661a55337e0e7ca7b1262b7298 Subproject commit b4d09b7cd942893c238d4152eeac1bbc822a0b13