[recommendations-and-nl-search-client-only | DONE | CHANGED]: Removed ssr - Deleted files server.ts, src/app/app.server.module.ts, src/main.server.ts, src/tsconfig.server.json and removed server references from files angular.json, package.json.

This commit is contained in:
Konstantina Galouni 2024-09-09 14:24:20 +03:00
parent 5c8c31ae45
commit fe32746cef
6 changed files with 1 additions and 238 deletions

View File

@ -212,77 +212,6 @@
"src/assets"
]
}
},
"server": {
"builder": "@angular-devkit/build-angular:server",
"options": {
"outputPath": "dist/eosc/server",
"main": "server.ts",
"tsConfig": "src/tsconfig.server.json",
"sourceMap": true,
"optimization": false,
"buildOptimizer": false
},
"configurations": {
"development": {
"outputHashing": "media",
"sourceMap": false,
"optimization": true,
"vendorChunk": true,
"buildOptimizer": true
},
"beta": {
"outputHashing": "media",
"fileReplacements": [
{
"replace": "src/environments/environment.ts",
"with": "src/environments/environment.beta.ts"
}
],
"sourceMap": false,
"optimization": true,
"buildOptimizer": true
},
"production": {
"outputHashing": "media",
"fileReplacements": [
{
"replace": "src/environments/environment.ts",
"with": "src/environments/environment.prod.ts"
}
],
"sourceMap": false,
"optimization": true,
"buildOptimizer": true
}
},
"defaultConfiguration": ""
},
"serve-ssr": {
"builder": "@nguniversal/builders:ssr-dev-server",
"options": {
"browserTarget": "eosc:build",
"serverTarget": "eosc:server"
},
"configurations": {
"production": {
"browserTarget": "eosc:build:production",
"serverTarget": "eosc:server:production"
}
}
},
"prerender": {
"builder": "@nguniversal/builders:prerender",
"options": {
"browserTarget": "eosc:build:production",
"serverTarget": "eosc:server:production",
"routes": [
"/"
]
},
"configurations": {
"production": {}
}
}
}
},

View File

@ -11,12 +11,6 @@
"webpack-bundle-analyzer": "ng build --stats-json && webpack-bundle-analyzer dist/eosc/browser/stats-es2015.json --host 0.0.0.0",
"test": "ng test",
"e2e": "ng e2e",
"dev:ssr": "ng run eosc:serve-ssr",
"serve:ssr": "node dist/eosc/server/main.js",
"build:ssr-dev": "npm run build-dev && ng run eosc:server:development",
"build:ssr-beta": "npm run build-beta && ng run eosc:server:beta",
"build:ssr-prod": "npm run build-prod && ng run eosc:server:production",
"prerender": "ng run eosc:prerender",
"after-build-clean": "rm -rf dist/eosc/browser/assets/common-assets/.git/ src/app/openaireLibrary/.git node_modules .angular .git*"
},
"private": true,
@ -31,12 +25,9 @@
"@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",
"clipboard": "^1.5.16",
"core-js": "^2.5.4",
"express": "^4.15.2",
"jquery": "^3.4.1",
"ng-recaptcha": "^12.0.2",
"prom-client": "^11.3.0",
@ -44,6 +35,7 @@
"ts-md5": "^1.2.0",
"tslib": "^2.0.0",
"uikit": "3.16.24",
"uuid": "^10.0.0",
"zone.js": "~0.13.1"
},
"devDependencies": {
@ -51,10 +43,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",
"@types/compression": "^1.7.0",
"@types/node": "^12.11.1",
"@types/jasmine": "~3.6.0",
"@types/jasminewd2": "~2.0.3",
"codelyzer": "^6.0.0",

110
server.ts
View File

@ -1,110 +0,0 @@
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";
// The Express app is exported so that it can be used by serverless Functions.
export function app() {
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 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
}));
server.set('view engine', 'html');
server.set('views', distFolder);
// Example Express Rest API endpoints
// server.get('/api/**', (req, res) => { });
// Serve static files from /browser
server.get('*.*', express.static(distFolder, {
maxAge: '1y'
}));
server.get('/metrics', (req, res) => {
res.set('Content-Type', prometheus.register.contentType);
res.end(prometheus.register.metrics());
});
// 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)
}
]
});
}
});
return server;
}
function run() {
const port = process.env.PORT || 4000;
// Start up the Node server
const server = app();
server.listen(port, () => {
console.log(`Node Express server listening on http://localhost:${port}`);
});
}
// Webpack will replace 'require' with '__webpack_require__'
// '__non_webpack_require__' is a proxy to Node 'require'
// The below code is to ensure that the server is run only when not requiring the bundle.
declare const __non_webpack_require__: NodeRequire;
const mainModule = __non_webpack_require__.main;
const moduleFilename = mainModule && mainModule.filename || '';
if (moduleFilename === __filename || moduleFilename.includes('iisnode')) {
run();
}
export * from './src/main.server';

View File

@ -1,14 +0,0 @@
import { NgModule } from '@angular/core';
import {ServerModule} from '@angular/platform-server';
import { AppModule } from './app.module';
import { AppComponent } from './app.component';
@NgModule({
imports: [
AppModule,
ServerModule
],
bootstrap: [AppComponent],
})
export class AppServerModule {}

View File

@ -1,15 +0,0 @@
/***************************************************************************************************
* Load `$localize` onto the global scope - used if i18n tags appear in Angular templates.
*/
import '@angular/localize/init';
import { enableProdMode } from '@angular/core';
import {properties} from './environments/environment';
if (properties.environment !== "development") {
enableProdMode();
}
export { AppServerModule } from './app/app.server.module';

View File

@ -1,16 +0,0 @@
{
"extends": "./tsconfig.app.json",
"compilerOptions": {
"outDir": "../out-tsc/app-server",
"types": [
"node"
]
},
"files": [
"main.server.ts",
"../server.ts"
],
"angularCompilerOptions": {
"entryModule": "./app/app.server.module#AppServerModule"
}
}