Skip to content

Commit 097b6b7

Browse files
authored
Ensure codebase is production-ready (#68)
* Frontend: Refactor config to env Make use of angular environments to ensure it serves the correct URLs on production. * Ensure production consistent URLs AWS load balancers are unable to trim off path (/api/server). Let's update the services themselves to contain these path prefixes. * User: Add logging * User: Modify health check route * Standardise server.ts across services * Reorder compose.yml
1 parent f85a63b commit 097b6b7

File tree

31 files changed

+218
-161
lines changed

31 files changed

+218
-161
lines changed

compose.yml

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,21 @@ services:
2424
networks:
2525
- gateway-network
2626
restart: always
27+
28+
broker:
29+
container_name: broker
30+
hostname: broker
31+
image: rabbitmq:4.0.2
32+
user: rabbitmq
33+
networks:
34+
- gateway-network
35+
healthcheck:
36+
test: rabbitmq-diagnostics check_port_connectivity
37+
interval: 30s
38+
timeout: 30s
39+
retries: 10
40+
start_period: 30s
41+
restart: always
2742

2843
question:
2944
container_name: question
@@ -123,21 +138,6 @@ services:
123138
- match-db-network
124139
restart: always
125140

126-
broker:
127-
container_name: broker
128-
hostname: broker
129-
image: rabbitmq:4.0.2
130-
user: rabbitmq
131-
networks:
132-
- gateway-network
133-
healthcheck:
134-
test: rabbitmq-diagnostics check_port_connectivity
135-
interval: 30s
136-
timeout: 30s
137-
retries: 10
138-
start_period: 30s
139-
restart: always
140-
141141
collaboration:
142142
container_name: collaboration
143143
image: collaboration

frontend/angular.json

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,13 @@
5151
"development": {
5252
"optimization": false,
5353
"extractLicenses": false,
54-
"sourceMap": true
54+
"sourceMap": true,
55+
"fileReplacements": [
56+
{
57+
"replace": "src/environments/environment.ts",
58+
"with": "src/environments/environment.development.ts"
59+
}
60+
]
5561
}
5662
},
5763
"defaultConfiguration": "production"

frontend/src/_interceptors/jwt.interceptor.spec.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { HttpTestingController, provideHttpClientTesting } from '@angular/common
33
import { HTTP_INTERCEPTORS, HttpClient } from '@angular/common/http';
44
import { JwtInterceptor } from './jwt.interceptor';
55
import { AuthenticationService } from '../_services/authentication.service';
6-
import { API_CONFIG } from '../app/api.config';
6+
import { environment } from '../environments/environment.development';
77

88
describe('JwtInterceptor', () => {
99
let httpMock: HttpTestingController;
@@ -34,9 +34,9 @@ describe('JwtInterceptor', () => {
3434
});
3535

3636
it('should add an Authorization header', () => {
37-
httpClient.get(`${API_CONFIG.baseUrl}/user/test`).subscribe();
37+
httpClient.get(`${environment.apiUrl}/user/test`).subscribe();
3838

39-
const httpRequest = httpMock.expectOne(`${API_CONFIG.baseUrl}/user/test`);
39+
const httpRequest = httpMock.expectOne(`${environment.apiUrl}/user/test`);
4040

4141
expect(httpRequest.request.headers.has('Authorization')).toBeTruthy();
4242
expect(httpRequest.request.headers.get('Authorization')).toBe('Bearer fake-jwt-token');
@@ -47,9 +47,9 @@ describe('JwtInterceptor', () => {
4747
userValue: {},
4848
});
4949

50-
httpClient.get(`${API_CONFIG.baseUrl}/user/test`).subscribe();
50+
httpClient.get(`${environment.apiUrl}/user/test`).subscribe();
5151

52-
const httpRequest = httpMock.expectOne(`${API_CONFIG.baseUrl}/user/test`);
52+
const httpRequest = httpMock.expectOne(`${environment.apiUrl}/user/test`);
5353

5454
expect(httpRequest.request.headers.has('Authorization')).toBeFalsy();
5555
});

frontend/src/_services/api.service.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { API_CONFIG } from '../app/api.config';
1+
import { environment } from '../environments/environment';
22

33
/**
44
* Abstract class that serves as a base for API services.
@@ -16,6 +16,6 @@ export abstract class ApiService {
1616
* the specified apiPath.
1717
*/
1818
get apiUrl(): string {
19-
return API_CONFIG.baseUrl + this.apiPath;
19+
return environment.apiUrl + this.apiPath;
2020
}
2121
}

frontend/src/_services/question.service.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import { ApiService } from './api.service';
1414
providedIn: 'root',
1515
})
1616
export class QuestionService extends ApiService {
17-
protected apiPath = 'question/questions';
17+
protected apiPath = 'question';
1818

1919
private httpOptions = {
2020
headers: new HttpHeaders({

frontend/src/app/api.config.ts

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

frontend/src/app/collaboration/editor/editor.component.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import { yCollab } from 'y-codemirror.next';
1515
import * as prettier from 'prettier';
1616
import * as prettierPluginEstree from 'prettier/plugins/estree';
1717
import { usercolors } from './user-colors';
18-
import { WEBSOCKET_CONFIG } from '../../api.config';
1918
import { AuthenticationService } from '../../../_services/authentication.service';
2019
import { RoomService } from '../room.service';
2120
// The 'prettier-plugin-java' package does not provide TypeScript declaration files.
@@ -28,6 +27,7 @@ import { SubmitDialogComponent } from '../submit-dialog/submit-dialog.component'
2827
import { ForfeitDialogComponent } from '../forfeit-dialog/forfeit-dialog.component';
2928
import { Router } from '@angular/router';
3029
import { awarenessData } from '../collab.model';
30+
import { environment } from '../../../environments/environment';
3131

3232
enum WebSocketCode {
3333
AUTH_FAILED = 4000,
@@ -98,7 +98,7 @@ export class EditorComponent implements AfterViewInit, OnInit, OnDestroy {
9898

9999
initConnection() {
100100
this.ydoc = new Y.Doc();
101-
const websocketUrl = WEBSOCKET_CONFIG.baseUrl + 'collaboration/';
101+
const websocketUrl = environment.wsUrl + 'collaboration/';
102102
this.wsProvider = new WebsocketProvider(websocketUrl, this.roomId, this.ydoc, {
103103
params: {
104104
accessToken: this.authService.userValue?.accessToken || '',
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export const environment = {
2+
apiUrl: 'http://localhost:8080/api/',
3+
wsUrl: 'ws://localhost:8080/api/',
4+
};
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export const environment = {
2+
apiUrl: 'https://app.peerprep.org/api/',
3+
wsUrl: 'wss://app.peerprep.org/api/',
4+
};

nginx/default.conf

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,23 +18,23 @@ server {
1818
listen 8080;
1919
server_name localhost;
2020

21-
location /api/question/ {
22-
proxy_pass http://question-api/;
21+
location /api/question {
22+
proxy_pass http://question-api;
2323
proxy_set_header Host $host;
2424
}
2525

26-
location /api/user/ {
27-
proxy_pass http://user-api/;
26+
location /api/user {
27+
proxy_pass http://user-api;
2828
proxy_set_header Host $host;
2929
}
3030

31-
location /api/match/ {
32-
proxy_pass http://match-api/;
31+
location /api/match {
32+
proxy_pass http://match-api;
3333
proxy_set_header Host $host;
3434
}
3535

36-
location /api/collaboration/ {
37-
proxy_pass http://collaboration-api/;
36+
location /api/collaboration {
37+
proxy_pass http://collaboration-api;
3838
proxy_set_header Host $host;
3939
proxy_http_version 1.1;
4040
proxy_set_header Upgrade $http_upgrade;

0 commit comments

Comments
 (0)