[angular-17 | WIP] upgrade angular core and cli to v17
This commit is contained in:
parent
2fa9d579fa
commit
87fda3194a
10
angular.json
10
angular.json
|
@ -183,18 +183,18 @@
|
|||
"serve": {
|
||||
"builder": "@angular-devkit/build-angular:dev-server",
|
||||
"options": {
|
||||
"browserTarget": "eosc:build"
|
||||
"buildTarget": "eosc:build"
|
||||
},
|
||||
"configurations": {
|
||||
"production": {
|
||||
"browserTarget": "eosc:build:production"
|
||||
"buildTarget": "eosc:build:production"
|
||||
}
|
||||
}
|
||||
},
|
||||
"extract-i18n": {
|
||||
"builder": "@angular-devkit/build-angular:extract-i18n",
|
||||
"options": {
|
||||
"browserTarget": "eosc:build"
|
||||
"buildTarget": "eosc:build"
|
||||
}
|
||||
},
|
||||
"test": {
|
||||
|
@ -259,7 +259,7 @@
|
|||
"defaultConfiguration": ""
|
||||
},
|
||||
"serve-ssr": {
|
||||
"builder": "@nguniversal/builders:ssr-dev-server",
|
||||
"builder": "@angular-devkit/build-angular:ssr-dev-server",
|
||||
"options": {
|
||||
"browserTarget": "eosc:build",
|
||||
"serverTarget": "eosc:server"
|
||||
|
@ -272,7 +272,7 @@
|
|||
}
|
||||
},
|
||||
"prerender": {
|
||||
"builder": "@nguniversal/builders:prerender",
|
||||
"builder": "@angular-devkit/build-angular:prerender",
|
||||
"options": {
|
||||
"browserTarget": "eosc:build:production",
|
||||
"serverTarget": "eosc:server:production",
|
||||
|
|
36
package.json
36
package.json
|
@ -21,19 +21,19 @@
|
|||
},
|
||||
"private": true,
|
||||
"dependencies": {
|
||||
"@angular/animations": "^16.1.8",
|
||||
"@angular/animations": "^17.3.11",
|
||||
"@angular/cdk": "^16.1.7",
|
||||
"@angular/common": "^16.1.8",
|
||||
"@angular/compiler": "^16.1.8",
|
||||
"@angular/core": "^16.1.8",
|
||||
"@angular/forms": "^16.1.8",
|
||||
"@angular/localize": "^16.1.8",
|
||||
"@angular/common": "^17.3.11",
|
||||
"@angular/compiler": "^17.3.11",
|
||||
"@angular/core": "^17.3.11",
|
||||
"@angular/forms": "^17.3.11",
|
||||
"@angular/localize": "^17.3.11",
|
||||
"@angular/material": "^16.1.7",
|
||||
"@angular/platform-browser": "^16.1.8",
|
||||
"@angular/platform-browser-dynamic": "^16.1.8",
|
||||
"@angular/platform-server": "^16.1.8",
|
||||
"@angular/router": "^16.1.8",
|
||||
"@nguniversal/express-engine": "^16.1.1",
|
||||
"@angular/platform-browser": "^17.3.11",
|
||||
"@angular/platform-browser-dynamic": "^17.3.11",
|
||||
"@angular/platform-server": "^17.3.11",
|
||||
"@angular/router": "^17.3.11",
|
||||
"@angular/ssr": "^17.3.8",
|
||||
"clipboard": "^1.5.16",
|
||||
"core-js": "^2.5.4",
|
||||
"express": "^4.15.2",
|
||||
|
@ -47,16 +47,16 @@
|
|||
"zone.js": "~0.14.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@angular-devkit/build-angular": "^16.1.7",
|
||||
"@angular/cli": "^16.1.7",
|
||||
"@angular/compiler-cli": "^16.1.8",
|
||||
"@angular/language-service": "^16.1.8",
|
||||
"@nguniversal/builders": "^16.1.1",
|
||||
"@types/express": "^4.17.0",
|
||||
"@angular-devkit/build-angular": "^17.3.8",
|
||||
"@angular/cli": "^17.3.8",
|
||||
"@angular/compiler-cli": "^17.3.11",
|
||||
"@angular/language-service": "^17.3.11",
|
||||
"@types/compression": "^1.7.0",
|
||||
"@types/node": "^12.11.1",
|
||||
"@types/express": "^4.17.0",
|
||||
"@types/jasmine": "~3.6.0",
|
||||
"@types/jasminewd2": "~2.0.3",
|
||||
"@types/node": "^12.11.1",
|
||||
"browser-sync": "^3.0.0",
|
||||
"codelyzer": "^6.0.0",
|
||||
"jasmine-core": "~3.8.0",
|
||||
"jasmine-spec-reporter": "~5.0.0",
|
||||
|
|
95
server.ts
95
server.ts
|
@ -1,31 +1,22 @@
|
|||
|
||||
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 { existsSync } from 'fs';
|
||||
import {Prometheus} from "./prometheus";
|
||||
import {Counter} from "prom-client";
|
||||
import {REQUEST, RESPONSE} from "./src/app/openaireLibrary/utils/tokens";
|
||||
import { CommonEngine } from '@angular/ssr';
|
||||
import * as express from 'express';
|
||||
import { existsSync } from 'node:fs';
|
||||
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.
|
||||
export function app() {
|
||||
export function app(): express.Express {
|
||||
const server = express();
|
||||
server.use(compression());
|
||||
const distFolder = join(process.cwd(), 'dist/eosc/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')
|
||||
: join(distFolder, 'index.html');
|
||||
|
||||
const prometheus: Prometheus = new Prometheus();
|
||||
|
||||
// Our Universal express-engine (found @ https://github.com/angular/universal/tree/master/modules/express-engine)
|
||||
server.engine('html', ngExpressEngine({
|
||||
bootstrap: AppServerModule,
|
||||
inlineCriticalCss: false
|
||||
}));
|
||||
const commonEngine = new CommonEngine();
|
||||
|
||||
server.set('view engine', 'html');
|
||||
server.set('views', distFolder);
|
||||
|
@ -37,58 +28,28 @@ export function app() {
|
|||
maxAge: '1y'
|
||||
}));
|
||||
|
||||
server.get('/metrics', (req, res) => {
|
||||
res.set('Content-Type', prometheus.register.contentType);
|
||||
res.end(prometheus.register.metrics());
|
||||
});
|
||||
// All regular routes use the Angular engine
|
||||
server.get('*', (req, res, next) => {
|
||||
const { protocol, originalUrl, baseUrl, headers } = req;
|
||||
|
||||
// All regular routes use the Universal engine
|
||||
server.get('*', (req, res) => {
|
||||
let start = new Date();
|
||||
let counter: Counter = prometheus.counters.get(req.path);
|
||||
if(counter !== undefined) {
|
||||
counter.inc(1, new Date());
|
||||
res.render(indexHtml, {
|
||||
req, providers: [
|
||||
{
|
||||
provide: APP_BASE_HREF,
|
||||
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)
|
||||
}
|
||||
]
|
||||
});
|
||||
}
|
||||
commonEngine
|
||||
.render({
|
||||
bootstrap,
|
||||
documentFilePath: indexHtml,
|
||||
url: `${protocol}://${headers.host}${originalUrl}`,
|
||||
publicPath: distFolder,
|
||||
providers: [
|
||||
{ provide: APP_BASE_HREF, useValue: baseUrl },],
|
||||
})
|
||||
.then((html) => res.send(html))
|
||||
.catch((err) => next(err));
|
||||
});
|
||||
|
||||
return server;
|
||||
}
|
||||
|
||||
function run() {
|
||||
const port = process.env.PORT || 4000;
|
||||
function run(): void {
|
||||
const port = process.env['PORT'] || 4000;
|
||||
|
||||
// Start up the Node server
|
||||
const server = app();
|
||||
|
@ -107,4 +68,4 @@ if (moduleFilename === __filename || moduleFilename.includes('iisnode')) {
|
|||
run();
|
||||
}
|
||||
|
||||
export * from './src/main.server';
|
||||
export default bootstrap;
|
||||
|
|
|
@ -1 +1 @@
|
|||
Subproject commit c8caa1277aa456aab7502614e5482b373d6858f0
|
||||
Subproject commit 5f691d18c4ed14f23c35cbdb9746d9d5cd71b221
|
Loading…
Reference in New Issue