[angular-18]: Update library and assets. Update node version. Use withFetch App module. Fix server.ts
This commit is contained in:
parent
349184a813
commit
142105f19a
|
@ -54,7 +54,7 @@
|
||||||
"@types/express": "^4.17.0",
|
"@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",
|
"@types/node": "^18.19.1",
|
||||||
"browser-sync": "^3.0.0",
|
"browser-sync": "^3.0.0",
|
||||||
"codelyzer": "^6.0.0",
|
"codelyzer": "^6.0.0",
|
||||||
"jasmine-core": "~3.8.0",
|
"jasmine-core": "~3.8.0",
|
||||||
|
@ -68,4 +68,4 @@
|
||||||
"ts-node": "~7.0.0",
|
"ts-node": "~7.0.0",
|
||||||
"typescript": "~5.4.0"
|
"typescript": "~5.4.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
44
server.ts
44
server.ts
|
@ -1,20 +1,20 @@
|
||||||
|
|
||||||
import 'zone.js/node';
|
import 'zone.js/node';
|
||||||
|
|
||||||
import { APP_BASE_HREF } from '@angular/common';
|
import {APP_BASE_HREF} from '@angular/common';
|
||||||
import { CommonEngine } from '@angular/ssr';
|
import {CommonEngine} from '@angular/ssr';
|
||||||
import * as express from 'express';
|
import * as express from 'express';
|
||||||
import { existsSync } from 'node:fs';
|
import {existsSync} from 'node:fs';
|
||||||
import { join } from 'node:path';
|
import {join} from 'node:path';
|
||||||
import bootstrap from './src/main.server';
|
import {AppServerModule} from './src/app/app.server.module';
|
||||||
|
import {REQUEST, RESPONSE} from "./src/app/openaireLibrary/utils/tokens";
|
||||||
|
|
||||||
// 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(): express.Express {
|
export function app(): express.Express {
|
||||||
const server = express();
|
const server = express();
|
||||||
const distFolder = join(process.cwd(), 'dist/monitor/browser');
|
const distFolder = join(process.cwd(), 'dist/monitor/browser');
|
||||||
const indexHtml = existsSync(join(distFolder, 'index.original.html'))
|
const indexHtml = existsSync(join(distFolder, 'index.original.html'))
|
||||||
? join(distFolder, 'index.original.html')
|
? join(distFolder, 'index.original.html')
|
||||||
: join(distFolder, 'index.html');
|
: join(distFolder, 'index.html');
|
||||||
|
|
||||||
const commonEngine = new CommonEngine();
|
const commonEngine = new CommonEngine();
|
||||||
|
|
||||||
|
@ -30,19 +30,23 @@ export function app(): express.Express {
|
||||||
|
|
||||||
// All regular routes use the Angular engine
|
// All regular routes use the Angular engine
|
||||||
server.get('*', (req, res, next) => {
|
server.get('*', (req, res, next) => {
|
||||||
const { protocol, originalUrl, baseUrl, headers } = req;
|
const {protocol, originalUrl, baseUrl, headers} = req;
|
||||||
|
|
||||||
commonEngine
|
commonEngine
|
||||||
.render({
|
.render({
|
||||||
bootstrap,
|
inlineCriticalCss: false,
|
||||||
documentFilePath: indexHtml,
|
bootstrap: AppServerModule,
|
||||||
url: `${protocol}://${headers.host}${originalUrl}`,
|
documentFilePath: indexHtml,
|
||||||
publicPath: distFolder,
|
url: `${protocol}://${headers.host}${originalUrl}`,
|
||||||
providers: [
|
publicPath: distFolder,
|
||||||
{ provide: APP_BASE_HREF, useValue: baseUrl },],
|
providers: [
|
||||||
})
|
{provide: APP_BASE_HREF, useValue: baseUrl},
|
||||||
.then((html) => res.send(html))
|
{provide: REQUEST, useValue: (req)},
|
||||||
.catch((err) => next(err));
|
{provide: RESPONSE, useValue: (res)}
|
||||||
|
]
|
||||||
|
})
|
||||||
|
.then((html) => res.status(200).send(html))
|
||||||
|
.catch((err) => res.status(500).send('Error during SSR'))
|
||||||
});
|
});
|
||||||
|
|
||||||
return server;
|
return server;
|
||||||
|
@ -67,5 +71,3 @@ const moduleFilename = mainModule && mainModule.filename || '';
|
||||||
if (moduleFilename === __filename || moduleFilename.includes('iisnode')) {
|
if (moduleFilename === __filename || moduleFilename.includes('iisnode')) {
|
||||||
run();
|
run();
|
||||||
}
|
}
|
||||||
|
|
||||||
export default bootstrap;
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import {APP_ID, NgModule} from '@angular/core';
|
import {APP_ID, NgModule} from '@angular/core';
|
||||||
import {FormsModule} from '@angular/forms';
|
import {FormsModule} from '@angular/forms';
|
||||||
import {CommonModule} from '@angular/common';
|
import {CommonModule} from '@angular/common';
|
||||||
import { HTTP_INTERCEPTORS, provideHttpClient, withInterceptorsFromDi } from "@angular/common/http";
|
import {HTTP_INTERCEPTORS, provideHttpClient, withFetch} from "@angular/common/http";
|
||||||
import {BrowserModule} from '@angular/platform-browser';
|
import {BrowserModule} from '@angular/platform-browser';
|
||||||
import {BrowserAnimationsModule} from '@angular/platform-browser/animations';
|
import {BrowserAnimationsModule} from '@angular/platform-browser/animations';
|
||||||
import {AppComponent} from './app.component';
|
import {AppComponent} from './app.component';
|
||||||
|
@ -52,7 +52,7 @@ import {HelperModule} from "./openaireLibrary/utils/helper/helper.module";
|
||||||
},
|
},
|
||||||
[{ provide: HTTP_INTERCEPTORS, useClass: TimeoutInterceptor, multi: true }],
|
[{ provide: HTTP_INTERCEPTORS, useClass: TimeoutInterceptor, multi: true }],
|
||||||
[{ provide: DEFAULT_TIMEOUT, useValue: 30000 }],
|
[{ provide: DEFAULT_TIMEOUT, useValue: 30000 }],
|
||||||
provideHttpClient(withInterceptorsFromDi())
|
provideHttpClient(withFetch())
|
||||||
] })
|
] })
|
||||||
//
|
//
|
||||||
export class AppModule {
|
export class AppModule {
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
Subproject commit af31fcfc372e314637b24a1646db013edf19bdec
|
Subproject commit ace2fca2e91eacd00cb7e2fcac4efa711d77a246
|
|
@ -1 +1 @@
|
||||||
Subproject commit eb0051dc347cdaa44476048dea9f6b61200f257f
|
Subproject commit a88e24accc23599b43577994011e424eb693e817
|
Loading…
Reference in New Issue