Skip to content

Commit

Permalink
release 2024.08.23.003
Browse files Browse the repository at this point in the history
release 2024.08.23.003
  • Loading branch information
wil92 authored Aug 23, 2024
2 parents d57defc + 776baf5 commit 8cab141
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 110 deletions.
2 changes: 2 additions & 0 deletions apps/blog/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { CommonEngine } from '@angular/ssr';
import express from 'express';
import { existsSync } from 'node:fs';
import { join } from 'node:path';
import compression from "compression";

import bootstrap from './src/main.server';

Expand All @@ -20,6 +21,7 @@ export function app(): express.Express {

server.set('view engine', 'html');
server.set('views', distFolder);
server.use(compression());

// Example Express Rest API endpoints
// server.get('/api/**', (req, res) => { });
Expand Down
65 changes: 0 additions & 65 deletions apps/blog/server.ts.bak

This file was deleted.

77 changes: 40 additions & 37 deletions apps/blog/src/app/app.module.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { BrowserModule } from '@angular/platform-browser';
import { BrowserModule, provideClientHydration } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { provideHttpClient, withInterceptorsFromDi } from '@angular/common/http';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
Expand Down Expand Up @@ -34,42 +34,45 @@ import { LoginRequestModalComponent } from './features/components/login-request-
import { PodcastModule } from './features/podcast';
import { UserModule } from './features/user';
import { FilterComponent } from './features/components/filter/filter.component';
import {NgOptimizedImage} from "@angular/common";
import { NgOptimizedImage } from "@angular/common";

@NgModule({ declarations: [
AppComponent,
HeaderComponent,
FilterComponent,
NewLabelComponent,
ScrollTopComponent,
CliComponent,
LoginButtonComponent,
LoginRequestModalComponent
],
bootstrap: [AppComponent], imports: [BrowserModule.withServerTransition({appId: 'serverApp'}),
AppRoutingModule,
BrowserAnimationsModule,
NgxsReduxDevtoolsPluginModule.forRoot(),
NgxsModule.forRoot([CommentState, AuthState, PostState, PodcastState, ConfigState, UserInfoState, SubscriptionState], {
developmentMode: !environment.production
}),
ReduxModule,
MaterialModule,
InfoModule,
SharedModule,
PodcastModule,
UserModule, NgOptimizedImage], providers: [
{
provide: ENVIRONMENT,
useValue: environment
},
{
provide: APOLLO_OPTIONS,
useFactory: createApollo,
deps: [HttpLink]
},
CommentService,
provideHttpClient(withInterceptorsFromDi())
] })
@NgModule({
declarations: [
AppComponent,
HeaderComponent,
FilterComponent,
NewLabelComponent,
ScrollTopComponent,
CliComponent,
LoginButtonComponent,
LoginRequestModalComponent
],
bootstrap: [AppComponent], imports: [BrowserModule.withServerTransition({appId: 'serverApp'}),
AppRoutingModule,
BrowserAnimationsModule,
NgxsReduxDevtoolsPluginModule.forRoot(),
NgxsModule.forRoot([CommentState, AuthState, PostState, PodcastState, ConfigState, UserInfoState, SubscriptionState], {
developmentMode: !environment.production
}),
ReduxModule,
MaterialModule,
InfoModule,
SharedModule,
PodcastModule,
UserModule, NgOptimizedImage], providers: [
{
provide: ENVIRONMENT,
useValue: environment
},
{
provide: APOLLO_OPTIONS,
useFactory: createApollo,
deps: [HttpLink]
},
CommentService,
provideHttpClient(withInterceptorsFromDi()),
provideClientHydration()
]
})
export class AppModule {
}
24 changes: 18 additions & 6 deletions apps/blog/src/app/features/post/post-resolver.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { Injectable } from '@angular/core';
import { Inject, Injectable, PLATFORM_ID } from '@angular/core';
import { ActivatedRouteSnapshot, Resolve } from '@angular/router';
import { isPlatformBrowser } from "@angular/common";

import { Store } from '@ngxs/store';
import { Observable } from 'rxjs';
import { Observable, of } from 'rxjs';
import { map, mergeMap } from 'rxjs/operators';

import {
Expand All @@ -14,9 +15,16 @@ import {
RecentCommentAction
} from '@dcs-libs/shared';

@Injectable({ providedIn: 'root' })
@Injectable({providedIn: 'root'})
export class PostResolver implements Resolve<Post> {
constructor(private store: Store) {

isBrowser: boolean;

constructor(
private store: Store,
@Inject(PLATFORM_ID) platformId: string,
) {
this.isBrowser = isPlatformBrowser(platformId);
}

resolve(route: ActivatedRouteSnapshot): Observable<Post> | Promise<Post> | Post {
Expand All @@ -25,8 +33,12 @@ export class PostResolver implements Resolve<Post> {
.pipe(
mergeMap(() => this.store.dispatch(new FetchPostUserLikeAction(route.paramMap.get('id'), user.id))),
mergeMap(() => this.store.dispatch(new RecentCommentAction())),
mergeMap( () => {
return this.store.dispatch(new FetchSimilarPostsAction(this.store.selectSnapshot(PostState.post).id));
mergeMap(() => {
// get similar posts only in the browser
if (this.isBrowser) {
return this.store.dispatch(new FetchSimilarPostsAction(this.store.selectSnapshot(PostState.post).id));
}
return of({});
}),
map(() => this.store.selectSnapshot(PostState.post))
);
Expand Down
15 changes: 13 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
"@ngxs/store": "18.1.1",
"@nx/angular": "19.5.7",
"apollo-angular": "7.0.2",
"compression": "^1.7.4",
"express": "^4.19.2",
"font-awesome": "4.7.0",
"graphql": "^16.8.1",
Expand Down Expand Up @@ -64,6 +65,7 @@
"@nx/web": "19.5.7",
"@nx/workspace": "19.5.7",
"@schematics/angular": "18.1.4",
"@types/compression": "^1.7.5",
"@types/express": "^4.17.17",
"@types/jest": "^29.4.0",
"@types/marked": "^4.0.8",
Expand Down

0 comments on commit 8cab141

Please sign in to comment.