Skip to content

Commit 4f9de1b

Browse files
author
Guilherme Andrade Pinto
committed
config endpoint
1 parent 085a0d5 commit 4f9de1b

File tree

7 files changed

+31
-19
lines changed

7 files changed

+31
-19
lines changed

ngsw-config.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
{
3131
"name": "api-tech-crunch-rss-reader",
3232
"urls": [
33-
"http://0.0.0.0:4000/api/posts"
33+
"https://dmdyyxzin2.execute-api.us-east-2.amazonaws.com/test"
3434
],
3535
"cacheConfig": {
3636
"strategy": "freshness",

src/app/posts/services/post.service.spec.ts

Lines changed: 0 additions & 13 deletions
This file was deleted.

src/app/posts/services/post.service.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { Injectable } from '@angular/core';
22
import { Observable } from 'rxjs';
33
import { Post } from '../models/post';
4-
import { HttpResponse, HttpClient } from '@angular/common/http';
4+
import { HttpResponse, HttpClient, HttpHeaders } from '@angular/common/http';
55

66
import { environment } from '../../../environments/environment';
77

@@ -15,6 +15,8 @@ export class PostService {
1515
constructor(private http: HttpClient) { }
1616

1717
findAll(): Observable<HttpResponse<Post[]>> {
18-
return this.http.get<Post[]>(`${this.baseUrl}/posts`, { observe: 'response' });
18+
return this.http.get<Post[]>(`${this.baseUrl}/posts`, {
19+
observe: 'response'
20+
});
1921
}
2022
}

src/app/shared/HttpInterceptorCors.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { Injectable, Injector } from '@angular/core';
2+
import { Route } from '@angular/router';
3+
import { HttpEvent, HttpInterceptor, HttpHandler, HttpRequest, HttpErrorResponse } from '@angular/common/http';
4+
import { Observable } from 'rxjs';
5+
6+
@Injectable()
7+
export class HttpInterceptorCors implements HttpInterceptor {
8+
constructor() {}
9+
10+
intercept(req: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
11+
const headers = req.headers
12+
.set('Access-Control-Allow-Origin', '*')
13+
.set('Access-Control-Allow-Headers', 'Content-Type');
14+
const authReq = req.clone({ headers });
15+
return next.handle(authReq);
16+
}
17+
}

src/app/shared/shared.module.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@ import {
1010
MatInputModule
1111
} from '@angular/material';
1212
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
13-
import { HttpClientModule } from '@angular/common/http';
13+
import { HttpClientModule, HTTP_INTERCEPTORS } from '@angular/common/http';
1414
import { SanitizeHtmlPipe } from './pipes/sanitize-html.pipe';
15+
import { HttpInterceptorCors } from './HttpInterceptorCors';
1516

1617
const MatModules = [
1718
MatToolbarModule,
@@ -39,5 +40,10 @@ const MatModules = [
3940
HttpClientModule,
4041
SanitizeHtmlPipe,
4142
],
43+
providers: [
44+
{ provide: HTTP_INTERCEPTORS,
45+
useClass: HttpInterceptorCors,
46+
multi: true}
47+
]
4248
})
4349
export class SharedModule { }

src/environments/environment.prod.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
export const environment = {
22
production: true,
3-
baseUrl: 'http://0.0.0.0:4000/api'
3+
baseUrl: 'https://dmdyyxzin2.execute-api.us-east-2.amazonaws.com/test'
44
};

src/environments/environment.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
export const environment = {
66
production: false,
7-
baseUrl: 'http://0.0.0.0:4000/api'
7+
baseUrl: 'https://dmdyyxzin2.execute-api.us-east-2.amazonaws.com/test'
88
};
99

1010
/*

0 commit comments

Comments
 (0)