diff --git a/package.json b/package.json index 0389103..31ec900 100644 --- a/package.json +++ b/package.json @@ -54,7 +54,7 @@ "@types/express": "^4.17.0", "@types/jasmine": "~3.6.0", "@types/jasminewd2": "~2.0.3", - "@types/node": "^16.18.50", + "@types/node": "^18.19.1", "browser-sync": "^3.0.0", "codelyzer": "^6.0.0", "jasmine-core": "~3.8.0", @@ -68,4 +68,4 @@ "ts-node": "~7.0.0", "typescript": "~5.4.0" } -} \ No newline at end of file +} diff --git a/server.ts b/server.ts index 48159d8..0ce9997 100644 --- a/server.ts +++ b/server.ts @@ -1,20 +1,20 @@ - import 'zone.js/node'; -import { APP_BASE_HREF } from '@angular/common'; -import { CommonEngine } from '@angular/ssr'; +import {APP_BASE_HREF} from '@angular/common'; +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'; +import {existsSync} from 'node:fs'; +import {join} from 'node:path'; +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. export function app(): express.Express { const server = express(); const distFolder = join(process.cwd(), 'dist/monitor/browser'); const indexHtml = existsSync(join(distFolder, 'index.original.html')) - ? join(distFolder, 'index.original.html') - : join(distFolder, 'index.html'); + ? join(distFolder, 'index.original.html') + : join(distFolder, 'index.html'); const commonEngine = new CommonEngine(); @@ -30,19 +30,23 @@ export function app(): express.Express { // All regular routes use the Angular engine server.get('*', (req, res, next) => { - const { protocol, originalUrl, baseUrl, headers } = req; + const {protocol, originalUrl, baseUrl, headers} = req; 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)); + .render({ + inlineCriticalCss: false, + bootstrap: AppServerModule, + documentFilePath: indexHtml, + url: `${protocol}://${headers.host}${originalUrl}`, + publicPath: distFolder, + providers: [ + {provide: APP_BASE_HREF, useValue: baseUrl}, + {provide: REQUEST, useValue: (req)}, + {provide: RESPONSE, useValue: (res)} + ] + }) + .then((html) => res.status(200).send(html)) + .catch((err) => res.status(500).send('Error during SSR')) }); return server; @@ -67,5 +71,3 @@ const moduleFilename = mainModule && mainModule.filename || ''; if (moduleFilename === __filename || moduleFilename.includes('iisnode')) { run(); } - -export default bootstrap; diff --git a/src/app/app.module.ts b/src/app/app.module.ts index 41f9350..aaeb7be 100755 --- a/src/app/app.module.ts +++ b/src/app/app.module.ts @@ -1,7 +1,7 @@ import {APP_ID, NgModule} from '@angular/core'; import {FormsModule} from '@angular/forms'; 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 {BrowserAnimationsModule} from '@angular/platform-browser/animations'; 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: DEFAULT_TIMEOUT, useValue: 30000 }], - provideHttpClient(withInterceptorsFromDi()) + provideHttpClient(withFetch()) ] }) // export class AppModule { diff --git a/src/app/openaireLibrary b/src/app/openaireLibrary index af31fcf..ace2fca 160000 --- a/src/app/openaireLibrary +++ b/src/app/openaireLibrary @@ -1 +1 @@ -Subproject commit af31fcfc372e314637b24a1646db013edf19bdec +Subproject commit ace2fca2e91eacd00cb7e2fcac4efa711d77a246 diff --git a/src/assets/common-assets b/src/assets/common-assets index eb0051d..a88e24a 160000 --- a/src/assets/common-assets +++ b/src/assets/common-assets @@ -1 +1 @@ -Subproject commit eb0051dc347cdaa44476048dea9f6b61200f257f +Subproject commit a88e24accc23599b43577994011e424eb693e817