Add express-engine
This commit is contained in:
@@ -25,3 +25,11 @@ Run `ng e2e` to execute the end-to-end tests via a platform of your choice. To u
|
|||||||
## Further help
|
## Further help
|
||||||
|
|
||||||
To get more help on the Angular CLI use `ng help` or go check out the [Angular CLI Overview and Command Reference](https://angular.io/cli) page.
|
To get more help on the Angular CLI use `ng help` or go check out the [Angular CLI Overview and Command Reference](https://angular.io/cli) page.
|
||||||
|
|
||||||
|
# Architecture
|
||||||
|
|
||||||
|
Wat wil ik?
|
||||||
|
- Angular
|
||||||
|
- Met SSR
|
||||||
|
- Keycloak
|
||||||
|
- Iets van een
|
||||||
|
|||||||
56
angular.json
56
angular.json
@@ -13,7 +13,7 @@
|
|||||||
"build": {
|
"build": {
|
||||||
"builder": "@angular-devkit/build-angular:browser",
|
"builder": "@angular-devkit/build-angular:browser",
|
||||||
"options": {
|
"options": {
|
||||||
"outputPath": "dist/ehbo-dronten",
|
"outputPath": "dist/ehbo-dronten/browser",
|
||||||
"index": "src/index.html",
|
"index": "src/index.html",
|
||||||
"main": "src/main.ts",
|
"main": "src/main.ts",
|
||||||
"polyfills": [
|
"polyfills": [
|
||||||
@@ -91,6 +91,60 @@
|
|||||||
],
|
],
|
||||||
"scripts": []
|
"scripts": []
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
"server": {
|
||||||
|
"builder": "@angular-devkit/build-angular:server",
|
||||||
|
"options": {
|
||||||
|
"outputPath": "dist/ehbo-dronten/server",
|
||||||
|
"main": "server.ts",
|
||||||
|
"tsConfig": "tsconfig.server.json"
|
||||||
|
},
|
||||||
|
"configurations": {
|
||||||
|
"production": {
|
||||||
|
"outputHashing": "media"
|
||||||
|
},
|
||||||
|
"development": {
|
||||||
|
"buildOptimizer": false,
|
||||||
|
"optimization": false,
|
||||||
|
"sourceMap": true,
|
||||||
|
"extractLicenses": false,
|
||||||
|
"vendorChunk": true
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"defaultConfiguration": "production"
|
||||||
|
},
|
||||||
|
"serve-ssr": {
|
||||||
|
"builder": "@nguniversal/builders:ssr-dev-server",
|
||||||
|
"configurations": {
|
||||||
|
"development": {
|
||||||
|
"browserTarget": "ehbo-dronten:build:development",
|
||||||
|
"serverTarget": "ehbo-dronten:server:development"
|
||||||
|
},
|
||||||
|
"production": {
|
||||||
|
"browserTarget": "ehbo-dronten:build:production",
|
||||||
|
"serverTarget": "ehbo-dronten:server:production"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"defaultConfiguration": "development"
|
||||||
|
},
|
||||||
|
"prerender": {
|
||||||
|
"builder": "@nguniversal/builders:prerender",
|
||||||
|
"options": {
|
||||||
|
"routes": [
|
||||||
|
"/"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"configurations": {
|
||||||
|
"production": {
|
||||||
|
"browserTarget": "ehbo-dronten:build:production",
|
||||||
|
"serverTarget": "ehbo-dronten:server:production"
|
||||||
|
},
|
||||||
|
"development": {
|
||||||
|
"browserTarget": "ehbo-dronten:build:development",
|
||||||
|
"serverTarget": "ehbo-dronten:server:development"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"defaultConfiguration": "production"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
1366
package-lock.json
generated
1366
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
14
package.json
14
package.json
@@ -6,7 +6,11 @@
|
|||||||
"start": "ng serve",
|
"start": "ng serve",
|
||||||
"build": "ng build",
|
"build": "ng build",
|
||||||
"watch": "ng build --watch --configuration development",
|
"watch": "ng build --watch --configuration development",
|
||||||
"test": "ng test"
|
"test": "ng test",
|
||||||
|
"dev:ssr": "ng run ehbo-dronten:serve-ssr",
|
||||||
|
"serve:ssr": "node dist/ehbo-dronten/server/main.js",
|
||||||
|
"build:ssr": "ng build && ng run ehbo-dronten:server",
|
||||||
|
"prerender": "ng run ehbo-dronten:prerender"
|
||||||
},
|
},
|
||||||
"private": true,
|
"private": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
@@ -17,7 +21,10 @@
|
|||||||
"@angular/forms": "^16.2.0",
|
"@angular/forms": "^16.2.0",
|
||||||
"@angular/platform-browser": "^16.2.0",
|
"@angular/platform-browser": "^16.2.0",
|
||||||
"@angular/platform-browser-dynamic": "^16.2.0",
|
"@angular/platform-browser-dynamic": "^16.2.0",
|
||||||
|
"@angular/platform-server": "^16.2.0",
|
||||||
"@angular/router": "^16.2.0",
|
"@angular/router": "^16.2.0",
|
||||||
|
"@nguniversal/express-engine": "^16.2.0",
|
||||||
|
"express": "^4.15.2",
|
||||||
"rxjs": "~7.8.0",
|
"rxjs": "~7.8.0",
|
||||||
"tslib": "^2.3.0",
|
"tslib": "^2.3.0",
|
||||||
"zone.js": "~0.13.0"
|
"zone.js": "~0.13.0"
|
||||||
@@ -26,7 +33,10 @@
|
|||||||
"@angular-devkit/build-angular": "^16.2.3",
|
"@angular-devkit/build-angular": "^16.2.3",
|
||||||
"@angular/cli": "~16.2.3",
|
"@angular/cli": "~16.2.3",
|
||||||
"@angular/compiler-cli": "^16.2.0",
|
"@angular/compiler-cli": "^16.2.0",
|
||||||
|
"@nguniversal/builders": "^16.2.0",
|
||||||
|
"@types/express": "^4.17.0",
|
||||||
"@types/jasmine": "~4.3.0",
|
"@types/jasmine": "~4.3.0",
|
||||||
|
"@types/node": "^16.11.7",
|
||||||
"jasmine-core": "~4.6.0",
|
"jasmine-core": "~4.6.0",
|
||||||
"karma": "~6.4.0",
|
"karma": "~6.4.0",
|
||||||
"karma-chrome-launcher": "~3.2.0",
|
"karma-chrome-launcher": "~3.2.0",
|
||||||
@@ -35,4 +45,4 @@
|
|||||||
"karma-jasmine-html-reporter": "~2.1.0",
|
"karma-jasmine-html-reporter": "~2.1.0",
|
||||||
"typescript": "~5.1.3"
|
"typescript": "~5.1.3"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
59
server.ts
Normal file
59
server.ts
Normal file
@@ -0,0 +1,59 @@
|
|||||||
|
import 'zone.js/node';
|
||||||
|
|
||||||
|
import { APP_BASE_HREF } from '@angular/common';
|
||||||
|
import { ngExpressEngine } from '@nguniversal/express-engine';
|
||||||
|
import * as express from 'express';
|
||||||
|
import { existsSync } from 'node:fs';
|
||||||
|
import { join } from 'node:path';
|
||||||
|
import { AppServerModule } from './src/main.server';
|
||||||
|
|
||||||
|
// 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/ehbo-dronten/browser');
|
||||||
|
const indexHtml = existsSync(join(distFolder, 'index.original.html')) ? 'index.original.html' : 'index';
|
||||||
|
|
||||||
|
// Our Universal express-engine (found @ https://github.com/angular/universal/tree/main/modules/express-engine)
|
||||||
|
server.engine('html', ngExpressEngine({
|
||||||
|
bootstrap: AppServerModule
|
||||||
|
}));
|
||||||
|
|
||||||
|
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'
|
||||||
|
}));
|
||||||
|
|
||||||
|
// All regular routes use the Universal engine
|
||||||
|
server.get('*', (req, res) => {
|
||||||
|
res.render(indexHtml, { req, providers: [{ provide: APP_BASE_HREF, useValue: req.baseUrl }] });
|
||||||
|
});
|
||||||
|
|
||||||
|
return server;
|
||||||
|
}
|
||||||
|
|
||||||
|
function run(): void {
|
||||||
|
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';
|
||||||
14
src/app/app.server.module.ts
Normal file
14
src/app/app.server.module.ts
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
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 {}
|
||||||
2
src/main.server.ts
Normal file
2
src/main.server.ts
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
|
||||||
|
export { AppServerModule } from './app/app.server.module';
|
||||||
14
tsconfig.server.json
Normal file
14
tsconfig.server.json
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
/* To learn more about this file see: https://angular.io/config/tsconfig. */
|
||||||
|
{
|
||||||
|
"extends": "./tsconfig.app.json",
|
||||||
|
"compilerOptions": {
|
||||||
|
"outDir": "./out-tsc/server",
|
||||||
|
"types": [
|
||||||
|
"node"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"files": [
|
||||||
|
"src/main.server.ts",
|
||||||
|
"server.ts"
|
||||||
|
]
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user