Skip to content

Commit

Permalink
hotfix
Browse files Browse the repository at this point in the history
  • Loading branch information
JuribaDev committed Aug 31, 2024
1 parent 3f1f984 commit 709067e
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 22 deletions.
11 changes: 7 additions & 4 deletions apps/client/nginx.conf
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,13 @@ http {
try_files $uri $uri/ /index.html;
}

location ~* ^(?!/assets/).*$ {
try_files $uri $uri/ /index.html;
location /api {
proxy_pass https://rnd-platform-server-app-p5qzcycuqa-ww.a.run.app;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}

error_page 404 /index.html;
}
}
6 changes: 6 additions & 0 deletions apps/client/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@
},
"configurations": {
"production": {
"fileReplacements": [
{
"replace": "apps/client/src/environments/environment.ts",
"with": "apps/client/src/environments/environment.prod.ts"
}
],
"budgets": [
{
"type": "initial",
Expand Down
18 changes: 5 additions & 13 deletions apps/client/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { existsSync } from 'node:fs';
import { join } from 'node:path';
import bootstrap from './src/main.server';

// The Express app is exported so that it can be used by serverless Functions.

export function app(): express.Express {
const server = express();
const distFolder = join(process.cwd(), 'dist/apps/client/browser');
Expand All @@ -20,17 +20,6 @@ export function app(): express.Express {
server.set('view engine', 'html');
server.set('views', distFolder);

// Example Express Rest API endpoints
// server.get('/api/**', (req, res) => { });
// Serve static files from /browser
server.get(
'*.*',
express.static(distFolder, {
maxAge: '1y',
})
);

// All regular routes use the Angular engine
server.get('*', (req, res, next) => {
const { protocol, originalUrl, baseUrl, headers } = req;

Expand All @@ -40,7 +29,10 @@ export function app(): express.Express {
documentFilePath: indexHtml,
url: `${protocol}://${headers.host}${originalUrl}`,
publicPath: distFolder,
providers: [{ provide: APP_BASE_HREF, useValue: baseUrl }],
providers: [
{ provide: APP_BASE_HREF, useValue: baseUrl },
{ provide: 'API_URL', useValue: process.env['API_URL'] + '/api/v1' },
],
})
.then((html) => res.send(html))
.catch((err) => next(err));
Expand Down
12 changes: 9 additions & 3 deletions apps/client/src/app/shared/api-client.service.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
import { Injectable } from '@angular/core';
import { Inject, Injectable, PLATFORM_ID } from '@angular/core';
import { HttpClient, HttpHeaders } from '@angular/common/http';
import { Observable } from 'rxjs';
import { TokenService } from './token.service';
import { LoginRequestDto, RegisterRequestDto, AuthResponseDto } from '../auth/dto/auth.dto';
import { PaginatedProductResponseDto } from '../product/dto/product.dto';
import { environment } from '../../environments/environment';
import { isPlatformBrowser } from '@angular/common';
import * as process from 'node:process';

@Injectable({
providedIn: 'root'
})
export class ApiClientService {
private baseUrl = environment.apiUrl;
baseUrl: string;

constructor(private http: HttpClient, private tokenService: TokenService) {}
constructor(@Inject(PLATFORM_ID) private platformId: NonNullable<unknown> ,private http: HttpClient, private tokenService: TokenService) {
this.baseUrl = isPlatformBrowser(this.platformId) ? environment.apiUrl : process.env['API_URL']+ '/api/v1' ;
}

private getHeaders(): HttpHeaders {
const token = this.tokenService.getToken();
Expand All @@ -22,6 +26,8 @@ export class ApiClientService {

// Auth endpoints
login(loginData: LoginRequestDto): Observable<AuthResponseDto> {
console.log(`Making login request to: ${this.baseUrl}/auth/login`);

return this.http.post<AuthResponseDto>(`${this.baseUrl}/auth/login`, loginData);
}

Expand Down
2 changes: 1 addition & 1 deletion apps/client/src/environments/environment.prod.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export const environment = {
production: true,
apiUrl: '/api/v1'
apiUrl: typeof window !== 'undefined' ? window.location.origin + '/api/v1' : '${API_URL}/api/v1'
};
2 changes: 1 addition & 1 deletion apps/server/src/shared/origins.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export const ORIGINS = [
"https://34.1.32.26",
"https://rnd-platform-client-app-p5qzcycuqa-ww.a.run.app",
"http://localhost",
"http://localhost:3000",
]

0 comments on commit 709067e

Please sign in to comment.