Switched to using Server Side Rendering
This commit is contained in:
1 parent
199b19459b
commit
06ab3b06bd
14 files changed
+485
-251
No files matched your search
+6
-1
@@ -30,7 +30,12 @@
|
|||||||
"@angular/material/prebuilt-themes/magenta-violet.css",
|
"@angular/material/prebuilt-themes/magenta-violet.css",
|
||||||
"src/styles.css"
|
"src/styles.css"
|
||||||
],
|
],
|
||||||
"scripts": []
|
"scripts": [],
|
||||||
|
"server": "src/main.server.ts",
|
||||||
|
"outputMode": "server",
|
||||||
|
"ssr": {
|
||||||
|
"entry": "src/server.ts"
|
||||||
|
}
|
||||||
},
|
},
|
||||||
"configurations": {
|
"configurations": {
|
||||||
"production": {
|
"production": {
|
||||||
|
|||||||
Generated
+203
-229
File diff suppressed because it is too large.
Load diff
+15
-9
@@ -6,22 +6,26 @@
|
|||||||
"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",
|
||||||
|
"serve:ssr:itzmineydev": "node dist/itzmineydev/server/server.mjs"
|
||||||
},
|
},
|
||||||
"private": true,
|
"private": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@angular/animations": "^19.0.0",
|
"@angular/animations": "^19.0.5",
|
||||||
"@angular/cdk": "^19.0.4",
|
"@angular/cdk": "^19.0.4",
|
||||||
"@angular/common": "^19.0.0",
|
"@angular/common": "^19.0.5",
|
||||||
"@angular/compiler": "^19.0.0",
|
"@angular/compiler": "^19.0.5",
|
||||||
"@angular/core": "^19.0.5",
|
"@angular/core": "^19.0.5",
|
||||||
"@angular/forms": "^19.0.0",
|
"@angular/forms": "^19.0.5",
|
||||||
"@angular/material": "^19.0.4",
|
"@angular/material": "^19.0.4",
|
||||||
"@angular/platform-browser": "^19.0.0",
|
"@angular/platform-browser": "^19.0.5",
|
||||||
"@angular/platform-browser-dynamic": "^19.0.0",
|
"@angular/platform-browser-dynamic": "^19.0.5",
|
||||||
"@angular/router": "^19.0.0",
|
"@angular/platform-server": "^19.0.5",
|
||||||
|
"@angular/router": "^19.0.5",
|
||||||
|
"@angular/ssr": "^19.0.6",
|
||||||
"@fortawesome/fontawesome-free": "^6.7.2",
|
"@fortawesome/fontawesome-free": "^6.7.2",
|
||||||
"@types/three": "^0.171.0",
|
"@types/three": "^0.171.0",
|
||||||
|
"express": "^4.18.2",
|
||||||
"ngx-device-detector": "^9.0.0",
|
"ngx-device-detector": "^9.0.0",
|
||||||
"react": "^19.0.0",
|
"react": "^19.0.0",
|
||||||
"rxjs": "~7.8.0",
|
"rxjs": "~7.8.0",
|
||||||
@@ -33,8 +37,10 @@
|
|||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@angular-devkit/build-angular": "^19.0.6",
|
"@angular-devkit/build-angular": "^19.0.6",
|
||||||
"@angular/cli": "^19.0.6",
|
"@angular/cli": "^19.0.6",
|
||||||
"@angular/compiler-cli": "^19.0.0",
|
"@angular/compiler-cli": "^19.0.5",
|
||||||
|
"@types/express": "^4.17.17",
|
||||||
"@types/jasmine": "~5.1.0",
|
"@types/jasmine": "~5.1.0",
|
||||||
|
"@types/node": "^18.18.0",
|
||||||
"jasmine-core": "~5.4.0",
|
"jasmine-core": "~5.4.0",
|
||||||
"karma": "~6.4.0",
|
"karma": "~6.4.0",
|
||||||
"karma-chrome-launcher": "~3.2.0",
|
"karma-chrome-launcher": "~3.2.0",
|
||||||
|
|||||||
@@ -1,6 +1,10 @@
|
|||||||
import {Component, OnInit, OnDestroy, AfterViewInit} from '@angular/core';
|
import {Component, OnInit, OnDestroy, AfterViewInit, Inject} from '@angular/core';
|
||||||
import { DeviceDetectorService } from 'ngx-device-detector';
|
import { DeviceDetectorService } from 'ngx-device-detector';
|
||||||
import {NgIf} from '@angular/common';
|
import {NgIf} from '@angular/common';
|
||||||
|
import { Meta, Title } from '@angular/platform-browser';
|
||||||
|
import { ActivatedRoute } from '@angular/router';
|
||||||
|
import { isPlatformBrowser } from '@angular/common';
|
||||||
|
import { PLATFORM_ID } from '@angular/core';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-about',
|
selector: 'app-about',
|
||||||
@@ -11,13 +15,32 @@ import {NgIf} from '@angular/common';
|
|||||||
styleUrls: ['./about.component.css']
|
styleUrls: ['./about.component.css']
|
||||||
})
|
})
|
||||||
export class AboutComponent implements OnInit, OnDestroy, AfterViewInit {
|
export class AboutComponent implements OnInit, OnDestroy, AfterViewInit {
|
||||||
constructor( private deviceService: DeviceDetectorService) {
|
constructor(
|
||||||
|
private deviceService: DeviceDetectorService,
|
||||||
|
private meta: Meta,
|
||||||
|
private title: Title,
|
||||||
|
private route: ActivatedRoute,
|
||||||
|
@Inject(PLATFORM_ID) private platformId: Object
|
||||||
|
) {
|
||||||
this.isMobile = this.deviceService.isMobile();
|
this.isMobile = this.deviceService.isMobile();
|
||||||
}
|
}
|
||||||
isMobile: boolean;
|
isMobile: boolean;
|
||||||
private vantaEffect: any;
|
private vantaEffect: any;
|
||||||
|
|
||||||
ngOnInit() {
|
ngOnInit() {
|
||||||
|
const metaData = this.route.snapshot.data['meta'];
|
||||||
|
if (metaData?.title) {
|
||||||
|
this.title.setTitle(metaData.title);
|
||||||
|
}
|
||||||
|
if (metaData?.description) {
|
||||||
|
this.meta.updateTag({ name: 'description', content: metaData.description });
|
||||||
|
}
|
||||||
|
if (metaData?.image) {
|
||||||
|
this.meta.updateTag({ property: 'og:image', content: metaData.image });
|
||||||
|
}
|
||||||
|
if (metaData?.url) {
|
||||||
|
this.meta.updateTag({ property: 'og:url', content: metaData.url });
|
||||||
|
}
|
||||||
window.addEventListener('resize', this.onResize.bind(this)); // Add resize listener for responsiveness
|
window.addEventListener('resize', this.onResize.bind(this)); // Add resize listener for responsiveness
|
||||||
|
|
||||||
const bgElement = document.getElementById('vanta-about-bg');
|
const bgElement = document.getElementById('vanta-about-bg');
|
||||||
@@ -26,17 +49,23 @@ export class AboutComponent implements OnInit, OnDestroy, AfterViewInit {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
ngAfterViewInit() {
|
ngAfterViewInit() {
|
||||||
|
if (isPlatformBrowser(this.platformId)) {
|
||||||
|
// Initialize VANTA effect only in the browser
|
||||||
this.initVanta();
|
this.initVanta();
|
||||||
this.resizeVanta();
|
this.resizeVanta();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
ngOnDestroy() {
|
ngOnDestroy() {
|
||||||
|
if (isPlatformBrowser(this.platformId)) {
|
||||||
if (this.vantaEffect) {
|
if (this.vantaEffect) {
|
||||||
this.vantaEffect.destroy(); // Clean up the effect on destroy
|
this.vantaEffect.destroy(); // Clean up the effect on destroy
|
||||||
}
|
}
|
||||||
window.removeEventListener('resize', this.onResize); // Remove the listener when the component is destroyed
|
window.removeEventListener('resize', this.onResize); // Remove the listener when the component is destroyed
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
initVanta() {
|
initVanta() {
|
||||||
|
if (isPlatformBrowser(this.platformId)) {
|
||||||
// Initialize the Vanta effect on the element with ID 'vanta-bg'
|
// Initialize the Vanta effect on the element with ID 'vanta-bg'
|
||||||
this.vantaEffect = window.VANTA.NET({
|
this.vantaEffect = window.VANTA.NET({
|
||||||
el: '#vanta-about-bg',
|
el: '#vanta-about-bg',
|
||||||
@@ -53,6 +82,7 @@ export class AboutComponent implements OnInit, OnDestroy, AfterViewInit {
|
|||||||
minHeight: window.innerHeight,
|
minHeight: window.innerHeight,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
onResize() {
|
onResize() {
|
||||||
// Update the minHeight and minWidth when the window is resized
|
// Update the minHeight and minWidth when the window is resized
|
||||||
|
|||||||
@@ -0,0 +1,14 @@
|
|||||||
|
import { mergeApplicationConfig, ApplicationConfig } from '@angular/core';
|
||||||
|
import { provideServerRendering } from '@angular/platform-server';
|
||||||
|
import { provideServerRoutesConfig } from '@angular/ssr';
|
||||||
|
import { appConfig } from './app.config';
|
||||||
|
import { serverRoutes } from './app.routes.server';
|
||||||
|
|
||||||
|
const serverConfig: ApplicationConfig = {
|
||||||
|
providers: [
|
||||||
|
provideServerRendering(),
|
||||||
|
provideServerRoutesConfig(serverRoutes)
|
||||||
|
]
|
||||||
|
};
|
||||||
|
|
||||||
|
export const config = mergeApplicationConfig(appConfig, serverConfig);
|
||||||
@@ -3,7 +3,8 @@ import { provideRouter } from '@angular/router';
|
|||||||
|
|
||||||
import { routes } from './app.routes';
|
import { routes } from './app.routes';
|
||||||
import { provideAnimationsAsync } from '@angular/platform-browser/animations/async';
|
import { provideAnimationsAsync } from '@angular/platform-browser/animations/async';
|
||||||
|
import { provideClientHydration, withEventReplay } from '@angular/platform-browser';
|
||||||
|
|
||||||
export const appConfig: ApplicationConfig = {
|
export const appConfig: ApplicationConfig = {
|
||||||
providers: [provideZoneChangeDetection({ eventCoalescing: true }), provideRouter(routes), provideAnimationsAsync()]
|
providers: [provideZoneChangeDetection({ eventCoalescing: true }), provideRouter(routes), provideAnimationsAsync(), provideClientHydration(withEventReplay())]
|
||||||
};
|
};
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
import {RenderMode, ServerRoute} from '@angular/ssr';
|
||||||
|
|
||||||
|
export const serverRoutes: ServerRoute[] = [
|
||||||
|
{
|
||||||
|
path: '',
|
||||||
|
renderMode: RenderMode.Client,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
path: 'about',
|
||||||
|
renderMode: RenderMode.Prerender,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
path: 'portfolio',
|
||||||
|
renderMode: RenderMode.Prerender,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
path: 'blog',
|
||||||
|
renderMode: RenderMode.Prerender,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
path: '**',
|
||||||
|
renderMode: RenderMode.Client,
|
||||||
|
}
|
||||||
|
]
|
||||||
@@ -8,7 +8,15 @@ export const routes: Routes = [
|
|||||||
{
|
{
|
||||||
path: '',
|
path: '',
|
||||||
redirectTo: '/about',
|
redirectTo: '/about',
|
||||||
pathMatch: 'full'
|
pathMatch: 'full',
|
||||||
|
data: {
|
||||||
|
meta: {
|
||||||
|
title: 'itzMiney\'s Home',
|
||||||
|
description: 'Welcome to itzMiney\'s Homepage! \bHere you can find my portfolio and other cool stuff.',
|
||||||
|
image: 'https://itzminey.dev/assets/ogimg.png',
|
||||||
|
url: 'https://itzminey.dev/about'
|
||||||
|
}
|
||||||
|
}
|
||||||
}, // Redirect default route to 'about'
|
}, // Redirect default route to 'about'
|
||||||
{
|
{
|
||||||
path: 'about',
|
path: 'about',
|
||||||
|
|||||||
@@ -1,6 +1,10 @@
|
|||||||
import {Component, OnInit, OnDestroy, AfterViewInit } from '@angular/core';
|
import {Component, OnInit, OnDestroy, AfterViewInit, Inject } from '@angular/core';
|
||||||
import { DeviceDetectorService } from 'ngx-device-detector';
|
import { DeviceDetectorService } from 'ngx-device-detector';
|
||||||
import {NgIf} from '@angular/common';
|
import {NgIf} from '@angular/common';
|
||||||
|
import {Meta, Title} from '@angular/platform-browser';
|
||||||
|
import {ActivatedRoute} from '@angular/router';
|
||||||
|
import { isPlatformBrowser } from '@angular/common';
|
||||||
|
import { PLATFORM_ID } from '@angular/core';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-blog',
|
selector: 'app-blog',
|
||||||
@@ -11,13 +15,32 @@ import {NgIf} from '@angular/common';
|
|||||||
styleUrl: './blog.component.css'
|
styleUrl: './blog.component.css'
|
||||||
})
|
})
|
||||||
export class BlogComponent implements OnInit, OnDestroy, AfterViewInit {
|
export class BlogComponent implements OnInit, OnDestroy, AfterViewInit {
|
||||||
constructor(private deviceService: DeviceDetectorService) {
|
constructor(
|
||||||
|
private deviceService: DeviceDetectorService,
|
||||||
|
private meta: Meta,
|
||||||
|
private title: Title,
|
||||||
|
private route: ActivatedRoute,
|
||||||
|
@Inject(PLATFORM_ID) private platformId: Object
|
||||||
|
) {
|
||||||
this.isMobile = this.deviceService.isMobile();
|
this.isMobile = this.deviceService.isMobile();
|
||||||
}
|
}
|
||||||
isMobile: boolean;
|
isMobile: boolean;
|
||||||
private vantaEffect: any;
|
private vantaEffect: any;
|
||||||
|
|
||||||
ngOnInit() {
|
ngOnInit() {
|
||||||
|
const metaData = this.route.snapshot.data['meta'];
|
||||||
|
if (metaData?.title) {
|
||||||
|
this.title.setTitle(metaData.title);
|
||||||
|
}
|
||||||
|
if (metaData?.description) {
|
||||||
|
this.meta.updateTag({ name: 'description', content: metaData.description });
|
||||||
|
}
|
||||||
|
if (metaData?.image) {
|
||||||
|
this.meta.updateTag({ property: 'og:image', content: metaData.image });
|
||||||
|
}
|
||||||
|
if (metaData?.url) {
|
||||||
|
this.meta.updateTag({ property: 'og:url', content: metaData.url });
|
||||||
|
}
|
||||||
window.addEventListener('resize', this.onResize.bind(this)); // Add resize listener for responsiveness
|
window.addEventListener('resize', this.onResize.bind(this)); // Add resize listener for responsiveness
|
||||||
|
|
||||||
const bgElement = document.getElementById('vanta-blog-bg');
|
const bgElement = document.getElementById('vanta-blog-bg');
|
||||||
@@ -27,17 +50,23 @@ export class BlogComponent implements OnInit, OnDestroy, AfterViewInit {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ngAfterViewInit() {
|
ngAfterViewInit() {
|
||||||
|
if (isPlatformBrowser(this.platformId)) {
|
||||||
|
// Initialize VANTA effect only in the browser
|
||||||
this.initVanta();
|
this.initVanta();
|
||||||
this.resizeVanta();
|
this.resizeVanta();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
ngOnDestroy() {
|
ngOnDestroy() {
|
||||||
|
if (isPlatformBrowser(this.platformId)) {
|
||||||
if (this.vantaEffect) {
|
if (this.vantaEffect) {
|
||||||
this.vantaEffect.destroy(); // Clean up the effect on destroy
|
this.vantaEffect.destroy(); // Clean up the effect on destroy
|
||||||
}
|
}
|
||||||
window.removeEventListener('resize', this.onResize); // Remove the listener when the component is destroyed
|
window.removeEventListener('resize', this.onResize); // Remove the listener when the component is destroyed
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
initVanta() {
|
initVanta() {
|
||||||
|
if (isPlatformBrowser(this.platformId)) {
|
||||||
// Initialize the Vanta effect on the element with ID 'vanta-bg'
|
// Initialize the Vanta effect on the element with ID 'vanta-bg'
|
||||||
this.vantaEffect = window.VANTA.NET({
|
this.vantaEffect = window.VANTA.NET({
|
||||||
el: '#vanta-blog-bg',
|
el: '#vanta-blog-bg',
|
||||||
@@ -56,6 +85,7 @@ export class BlogComponent implements OnInit, OnDestroy, AfterViewInit {
|
|||||||
backgroundColor: 0x191522
|
backgroundColor: 0x191522
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
onResize() {
|
onResize() {
|
||||||
// Update the minHeight and minWidth when the window is resized
|
// Update the minHeight and minWidth when the window is resized
|
||||||
|
|||||||
@@ -1,4 +1,9 @@
|
|||||||
import {Component, OnInit, OnDestroy, AfterViewInit } from '@angular/core';
|
import {Component, OnInit, OnDestroy, AfterViewInit, Inject} from '@angular/core';
|
||||||
|
import {DeviceDetectorService} from 'ngx-device-detector';
|
||||||
|
import {Meta, Title} from '@angular/platform-browser';
|
||||||
|
import {ActivatedRoute} from '@angular/router';
|
||||||
|
import { isPlatformBrowser } from '@angular/common';
|
||||||
|
import { PLATFORM_ID } from '@angular/core';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-not-found',
|
selector: 'app-not-found',
|
||||||
@@ -8,10 +13,32 @@ import {Component, OnInit, OnDestroy, AfterViewInit } from '@angular/core';
|
|||||||
})
|
})
|
||||||
|
|
||||||
export class NotFoundComponent implements OnInit, OnDestroy, AfterViewInit {
|
export class NotFoundComponent implements OnInit, OnDestroy, AfterViewInit {
|
||||||
|
constructor(
|
||||||
|
private deviceService: DeviceDetectorService,
|
||||||
|
private meta: Meta,
|
||||||
|
private title: Title,
|
||||||
|
private route: ActivatedRoute,
|
||||||
|
@Inject(PLATFORM_ID) private platformId: Object
|
||||||
|
) {
|
||||||
|
this.isMobile = this.deviceService.isMobile();
|
||||||
|
}
|
||||||
|
isMobile: boolean;
|
||||||
private vantaEffect: any;
|
private vantaEffect: any;
|
||||||
|
|
||||||
ngOnInit() {
|
ngOnInit() {
|
||||||
|
const metaData = this.route.snapshot.data['meta'];
|
||||||
|
if (metaData?.title) {
|
||||||
|
this.title.setTitle(metaData.title);
|
||||||
|
}
|
||||||
|
if (metaData?.description) {
|
||||||
|
this.meta.updateTag({ name: 'description', content: metaData.description });
|
||||||
|
}
|
||||||
|
if (metaData?.image) {
|
||||||
|
this.meta.updateTag({ property: 'og:image', content: metaData.image });
|
||||||
|
}
|
||||||
|
if (metaData?.url) {
|
||||||
|
this.meta.updateTag({ property: 'og:url', content: metaData.url });
|
||||||
|
}
|
||||||
window.addEventListener('resize', this.onResize.bind(this)); // Add resize listener for responsiveness
|
window.addEventListener('resize', this.onResize.bind(this)); // Add resize listener for responsiveness
|
||||||
|
|
||||||
const bgElement = document.getElementById('vanta-not-found-bg');
|
const bgElement = document.getElementById('vanta-not-found-bg');
|
||||||
@@ -21,17 +48,23 @@ export class NotFoundComponent implements OnInit, OnDestroy, AfterViewInit {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ngAfterViewInit() {
|
ngAfterViewInit() {
|
||||||
|
if (isPlatformBrowser(this.platformId)) {
|
||||||
|
// Initialize VANTA effect only in the browser
|
||||||
this.initVanta();
|
this.initVanta();
|
||||||
this.resizeVanta();
|
this.resizeVanta();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
ngOnDestroy() {
|
ngOnDestroy() {
|
||||||
|
if (isPlatformBrowser(this.platformId)) {
|
||||||
if (this.vantaEffect) {
|
if (this.vantaEffect) {
|
||||||
this.vantaEffect.destroy(); // Clean up the effect on destroy
|
this.vantaEffect.destroy(); // Clean up the effect on destroy
|
||||||
}
|
}
|
||||||
window.removeEventListener('resize', this.onResize); // Remove the listener when the component is destroyed
|
window.removeEventListener('resize', this.onResize); // Remove the listener when the component is destroyed
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
initVanta() {
|
initVanta() {
|
||||||
|
if (isPlatformBrowser(this.platformId)) {
|
||||||
// Initialize the Vanta effect on the element with ID 'vanta-bg'
|
// Initialize the Vanta effect on the element with ID 'vanta-bg'
|
||||||
this.vantaEffect = window.VANTA.NET({
|
this.vantaEffect = window.VANTA.NET({
|
||||||
el: '#vanta-not-found-bg',
|
el: '#vanta-not-found-bg',
|
||||||
@@ -50,6 +83,7 @@ export class NotFoundComponent implements OnInit, OnDestroy, AfterViewInit {
|
|||||||
backgroundColor: 0x191522
|
backgroundColor: 0x191522
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
onResize() {
|
onResize() {
|
||||||
// Update the minHeight and minWidth when the window is resized
|
// Update the minHeight and minWidth when the window is resized
|
||||||
|
|||||||
@@ -1,6 +1,10 @@
|
|||||||
import {AfterViewInit, Component, OnDestroy, OnInit} from '@angular/core';
|
import {AfterViewInit, Component, OnDestroy, OnInit, Inject} from '@angular/core';
|
||||||
import { DeviceDetectorService } from 'ngx-device-detector';
|
import { DeviceDetectorService } from 'ngx-device-detector';
|
||||||
import {NgIf} from '@angular/common';
|
import {NgIf} from '@angular/common';
|
||||||
|
import {Meta, Title} from '@angular/platform-browser';
|
||||||
|
import {ActivatedRoute} from '@angular/router';
|
||||||
|
import { isPlatformBrowser } from '@angular/common';
|
||||||
|
import { PLATFORM_ID } from '@angular/core';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-portfolio',
|
selector: 'app-portfolio',
|
||||||
@@ -11,13 +15,32 @@ import {NgIf} from '@angular/common';
|
|||||||
styleUrl: './portfolio.component.css'
|
styleUrl: './portfolio.component.css'
|
||||||
})
|
})
|
||||||
export class PortfolioComponent implements OnInit, OnDestroy, AfterViewInit {
|
export class PortfolioComponent implements OnInit, OnDestroy, AfterViewInit {
|
||||||
constructor(private deviceService: DeviceDetectorService) {
|
constructor(
|
||||||
|
private deviceService: DeviceDetectorService,
|
||||||
|
private meta: Meta,
|
||||||
|
private title: Title,
|
||||||
|
private route: ActivatedRoute,
|
||||||
|
@Inject(PLATFORM_ID) private platformId: Object
|
||||||
|
) {
|
||||||
this.isMobile = this.deviceService.isMobile();
|
this.isMobile = this.deviceService.isMobile();
|
||||||
}
|
}
|
||||||
isMobile: boolean;
|
isMobile: boolean;
|
||||||
private vantaEffect: any;
|
private vantaEffect: any;
|
||||||
|
|
||||||
ngOnInit() {
|
ngOnInit() {
|
||||||
|
const metaData = this.route.snapshot.data['meta'];
|
||||||
|
if (metaData?.title) {
|
||||||
|
this.title.setTitle(metaData.title);
|
||||||
|
}
|
||||||
|
if (metaData?.description) {
|
||||||
|
this.meta.updateTag({ name: 'description', content: metaData.description });
|
||||||
|
}
|
||||||
|
if (metaData?.image) {
|
||||||
|
this.meta.updateTag({ property: 'og:image', content: metaData.image });
|
||||||
|
}
|
||||||
|
if (metaData?.url) {
|
||||||
|
this.meta.updateTag({ property: 'og:url', content: metaData.url });
|
||||||
|
}
|
||||||
window.addEventListener('resize', this.onResize.bind(this)); // Add resize listener for responsiveness
|
window.addEventListener('resize', this.onResize.bind(this)); // Add resize listener for responsiveness
|
||||||
|
|
||||||
const bgElement = document.getElementById('vanta-portfolio-bg');
|
const bgElement = document.getElementById('vanta-portfolio-bg');
|
||||||
@@ -27,17 +50,23 @@ export class PortfolioComponent implements OnInit, OnDestroy, AfterViewInit {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ngAfterViewInit() {
|
ngAfterViewInit() {
|
||||||
|
if (isPlatformBrowser(this.platformId)) {
|
||||||
|
// Initialize VANTA effect only in the browser
|
||||||
this.initVanta();
|
this.initVanta();
|
||||||
this.resizeVanta();
|
this.resizeVanta();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
ngOnDestroy() {
|
ngOnDestroy() {
|
||||||
|
if (isPlatformBrowser(this.platformId)) {
|
||||||
if (this.vantaEffect) {
|
if (this.vantaEffect) {
|
||||||
this.vantaEffect.destroy(); // Clean up the effect on destroy
|
this.vantaEffect.destroy(); // Clean up the effect on destroy
|
||||||
}
|
}
|
||||||
window.removeEventListener('resize', this.onResize); // Remove the listener when the component is destroyed
|
window.removeEventListener('resize', this.onResize); // Remove the listener when the component is destroyed
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
initVanta() {
|
initVanta() {
|
||||||
|
if (isPlatformBrowser(this.platformId)) {
|
||||||
// Initialize the Vanta effect on the element with ID 'vanta-bg'
|
// Initialize the Vanta effect on the element with ID 'vanta-bg'
|
||||||
this.vantaEffect = window.VANTA.NET({
|
this.vantaEffect = window.VANTA.NET({
|
||||||
el: '#vanta-portfolio-bg',
|
el: '#vanta-portfolio-bg',
|
||||||
@@ -56,6 +85,7 @@ export class PortfolioComponent implements OnInit, OnDestroy, AfterViewInit {
|
|||||||
backgroundColor: 0x191522
|
backgroundColor: 0x191522
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
onResize() {
|
onResize() {
|
||||||
// Update the minHeight and minWidth when the window is resized
|
// Update the minHeight and minWidth when the window is resized
|
||||||
|
|||||||
@@ -0,0 +1,8 @@
|
|||||||
|
import { bootstrapApplication } from '@angular/platform-browser';
|
||||||
|
import { AppComponent } from './app/app.component';
|
||||||
|
import { config } from './app/app.config.server';
|
||||||
|
import { platformServer } from '@angular/platform-server';
|
||||||
|
|
||||||
|
const bootstrap = () => bootstrapApplication(AppComponent, config);
|
||||||
|
|
||||||
|
export default bootstrap;
|
||||||
@@ -0,0 +1,66 @@
|
|||||||
|
import {
|
||||||
|
AngularNodeAppEngine,
|
||||||
|
createNodeRequestHandler,
|
||||||
|
isMainModule,
|
||||||
|
writeResponseToNodeResponse,
|
||||||
|
} from '@angular/ssr/node';
|
||||||
|
import express from 'express';
|
||||||
|
import { dirname, resolve } from 'node:path';
|
||||||
|
import { fileURLToPath } from 'node:url';
|
||||||
|
|
||||||
|
const serverDistFolder = dirname(fileURLToPath(import.meta.url));
|
||||||
|
const browserDistFolder = resolve(serverDistFolder, '../browser');
|
||||||
|
|
||||||
|
const app = express();
|
||||||
|
const angularApp = new AngularNodeAppEngine();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Example Express Rest API endpoints can be defined here.
|
||||||
|
* Uncomment and define endpoints as necessary.
|
||||||
|
*
|
||||||
|
* Example:
|
||||||
|
* ```ts
|
||||||
|
* app.get('/api/**', (req, res) => {
|
||||||
|
* // Handle API request
|
||||||
|
* });
|
||||||
|
* ```
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Serve static files from /browser
|
||||||
|
*/
|
||||||
|
app.use(
|
||||||
|
express.static(browserDistFolder, {
|
||||||
|
maxAge: '1y',
|
||||||
|
index: false,
|
||||||
|
redirect: false,
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handle all other requests by rendering the Angular application.
|
||||||
|
*/
|
||||||
|
app.use('/**', (req, res, next) => {
|
||||||
|
angularApp
|
||||||
|
.handle(req)
|
||||||
|
.then((response) =>
|
||||||
|
response ? writeResponseToNodeResponse(response, res) : next(),
|
||||||
|
)
|
||||||
|
.catch(next);
|
||||||
|
});
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Start the server if this module is the main entry point.
|
||||||
|
* The server listens on the port defined by the `PORT` environment variable, or defaults to 4000.
|
||||||
|
*/
|
||||||
|
if (isMainModule(import.meta.url)) {
|
||||||
|
const port = process.env['PORT'] || 4000;
|
||||||
|
app.listen(port, () => {
|
||||||
|
console.log(`Node Express server listening on http://localhost:${port}`);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The request handler used by the Angular CLI (dev-server and during build).
|
||||||
|
*/
|
||||||
|
export const reqHandler = createNodeRequestHandler(app);
|
||||||
+6
-2
@@ -4,10 +4,14 @@
|
|||||||
"extends": "./tsconfig.json",
|
"extends": "./tsconfig.json",
|
||||||
"compilerOptions": {
|
"compilerOptions": {
|
||||||
"outDir": "./out-tsc/app",
|
"outDir": "./out-tsc/app",
|
||||||
"types": []
|
"types": [
|
||||||
|
"node"
|
||||||
|
]
|
||||||
},
|
},
|
||||||
"files": [
|
"files": [
|
||||||
"src/main.ts"
|
"src/main.ts",
|
||||||
|
"src/main.server.ts",
|
||||||
|
"src/server.ts"
|
||||||
],
|
],
|
||||||
"include": [
|
"include": [
|
||||||
"src/**/*.d.ts"
|
"src/**/*.d.ts"
|
||||||
|
|||||||
Reference in new issue
Block a user