Skip to content

Commit bef3a17

Browse files
committed
video-29: implemted everythiing for a Deployment to aws elastic beanstalk
1 parent 02a2fa6 commit bef3a17

17 files changed

+73
-14
lines changed

api/package-lock.json

Lines changed: 15 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
"scripts": {
99
"prebuild": "rimraf dist",
1010
"build": "nest build",
11+
"build:prod": "cd ../frontend && ng build --prod --output-path ../api/dist/frontend && cd ../api && nest build",
1112
"format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"",
1213
"start": "nest start",
1314
"start:dev": "nest start --watch",
@@ -27,6 +28,7 @@
2728
"@nestjs/jwt": "^7.0.0",
2829
"@nestjs/passport": "^7.0.0",
2930
"@nestjs/platform-express": "^7.2.0",
31+
"@nestjs/serve-static": "^2.1.3",
3032
"@nestjs/typeorm": "^7.0.0",
3133
"bcrypt": "^4.0.1",
3234
"nestjs-typeorm-paginate": "^2.0.3",

api/src/app.module.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,14 @@ import {TypeOrmModule} from '@nestjs/typeorm';
66
import { UserModule } from './user/user.module';
77
import { AuthModule } from './auth/auth.module';
88
import { BlogModule } from './blog/blog.module';
9+
import { ServeStaticModule } from '@nestjs/serve-static/dist/serve-static.module';
10+
import { join } from 'path';
911

1012
@Module({
1113
imports: [
14+
ServeStaticModule.forRoot({
15+
rootPath: join(__dirname, './', 'frontend'),
16+
}),
1217
ConfigModule.forRoot({isGlobal: true}),
1318
TypeOrmModule.forRoot({
1419
type: 'postgres',

api/src/main.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@ import { AppModule } from './app.module';
44
async function bootstrap() {
55
const app = await NestFactory.create(AppModule);
66
app.setGlobalPrefix('api');
7-
await app.listen(3000);
7+
await app.listen(process.env.PORT || 3000);
88
}
99
bootstrap();
6.93 KB
Loading

frontend/src/app/app.module.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import { UserProfileComponent } from './components/user/user-profile/user-profil
2828
import { AllBlogEntriesComponent } from './components/blog-entry/all-blog-entries/all-blog-entries.component';
2929
import { CreateBlogEntryComponent } from './components/blog-entry/create-blog-entry/create-blog-entry.component';
3030
import { ViewBlogEntryComponent } from './components/blog-entry/view-blog-entry/view-blog-entry.component';
31+
import { WINDOW_PROVIDERS } from './window-token';
3132

3233
@NgModule({
3334
declarations: [
@@ -63,6 +64,7 @@ import { ViewBlogEntryComponent } from './components/blog-entry/view-blog-entry/
6364
MarkdownModule.forRoot()
6465
],
6566
providers: [
67+
WINDOW_PROVIDERS,
6668
JwtHelperService,
6769
{ provide: JWT_OPTIONS, useValue: JWT_OPTIONS },
6870
{

frontend/src/app/components/blog-entry/all-blog-entries/all-blog-entries.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<div style="display: flex;">
44
<div>
55
<img *ngIf="blogEntry.headerImage !== null; else placeholderImage"
6-
src="http://localhost:3000/api/blog-entries/image/{{blogEntry.headerImage}}">
6+
src="{{origin}}/api/blog-entries/image/{{blogEntry.headerImage}}">
77
<ng-template #placeholderImage>
88
<img src="../../../assets/placeholders/placeholder-blog-entry.png">
99
</ng-template>

frontend/src/app/components/blog-entry/all-blog-entries/all-blog-entries.component.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1+
import { Inject } from '@angular/core';
12
import { Component, EventEmitter, Input, OnInit, Output, ViewChild } from '@angular/core';
23
import { MatPaginator, PageEvent } from '@angular/material/paginator';
34
import { Router } from '@angular/router';
45
import { Observable } from 'rxjs';
56
import { BlogEntriesPageable } from 'src/app/model/blog-entry.interface';
67
import { BlogService } from 'src/app/services/blog-service/blog.service';
8+
import { WINDOW } from 'src/app/window-token';
79

810
@Component({
911
selector: 'app-all-blog-entries',
@@ -17,7 +19,9 @@ export class AllBlogEntriesComponent {
1719

1820
pageEvent: PageEvent;
1921

20-
constructor(private router: Router) { }
22+
origin = this.window.location.origin;
23+
24+
constructor(private router: Router, @Inject(WINDOW) private window: Window) { }
2125

2226
onPaginateChange(event: PageEvent) {
2327
event.pageIndex = event.pageIndex + 1;

frontend/src/app/components/blog-entry/create-blog-entry/create-blog-entry.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<div style="width: 80%;">
66
<mat-card>
77
<mat-card-content>
8-
<img *ngIf="form.get('headerImage').value" src="http://localhost:3000/api/blog-entries/image/{{form.get('headerImage').value}}">
8+
<img *ngIf="form.get('headerImage').value" src="{{origin}}/api/blog-entries/image/{{form.get('headerImage').value}}">
99
<ul>
1010
<li>
1111
<mat-progress-bar [value]="file.progress"></mat-progress-bar>

frontend/src/app/components/blog-entry/create-blog-entry/create-blog-entry.component.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
import { HttpErrorResponse, HttpEventType } from '@angular/common/http';
2+
import { Inject } from '@angular/core';
23
import { Component, ElementRef, OnInit, ViewChild } from '@angular/core';
34
import { FormBuilder, FormGroup, Validators } from '@angular/forms';
45
import { Router } from '@angular/router';
56
import { of } from 'rxjs';
67
import { catchError, map, tap } from 'rxjs/operators';
78
import { BlogService } from 'src/app/services/blog-service/blog.service';
9+
import { WINDOW } from 'src/app/window-token';
810

911
export interface File {
1012
data: any;
@@ -29,11 +31,13 @@ export class CreateBlogEntryComponent implements OnInit {
2931

3032
form: FormGroup;
3133

34+
origin = this.window.location.origin;
3235

3336
constructor(
3437
private formBuilder: FormBuilder,
3538
private blogService: BlogService,
36-
private router: Router
39+
private router: Router,
40+
@Inject(WINDOW) private window: Window
3741
) { }
3842

3943
ngOnInit(): void {

0 commit comments

Comments
 (0)