Skip to content

Commit

Permalink
implemented enviroment variables for production so se4rver doesnt use…
Browse files Browse the repository at this point in the history
… localhost
  • Loading branch information
Dymoxz committed Nov 27, 2024
1 parent 5da11cc commit 349b019
Show file tree
Hide file tree
Showing 17 changed files with 115 additions and 3 deletions.
6 changes: 6 additions & 0 deletions apps/InstrumentRental-web/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@
},
"configurations": {
"production": {
"fileReplacements": [
{
"replace": "libs/shared/util-env/src/lib/env.development.ts",
"with": "libs/shared/util-env/src/lib/env.production.ts"
}
],
"budgets": [
{
"type": "initial",
Expand Down
2 changes: 1 addition & 1 deletion apps/data-api/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { Logger } from '@nestjs/common';
import { NestFactory } from '@nestjs/core';
import { AppModule } from './app/app.module';
import { CorsOptions } from '@nestjs/common/interfaces/external/cors-options.interface';
import { ApiResponseInterceptor } from '../../../libs/backend/dto/src/lib/api-response.interceptor';
import { ApiResponseInterceptor } from '@InstrumentRental/backend/dto'

async function bootstrap() {
const app = await NestFactory.create(AppModule);
Expand Down
1 change: 1 addition & 0 deletions libs/backend/dto/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export * from './lib/dto.module';
export * from './lib/instrument.dto'
export * from './lib/api-response.interceptor'
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { Observable, throwError } from 'rxjs';
import { HttpClient, HttpErrorResponse } from '@angular/common/http';
import { map, catchError, tap } from 'rxjs/operators';
import { catchError, map, tap } from 'rxjs/operators';
import { ApiResponse, IInstrument } from '@InstrumentRental/shared/api';
import { Injectable } from '@angular/core';
import { env } from '@InstrumentRental/shared/util-env';

/**
* See https://angular.io/guide/http#requesting-data-from-a-server
Expand All @@ -18,7 +19,10 @@ export const httpOptions = {
*/
@Injectable()
export class InstrumentService {
endpoint = 'http://localhost:3000/api/instrument';
/*
endpoint = 'http://localhost:3000/api/instrument';
*/
endpoint = env.dataApiUrl + '/instrument';

constructor(private readonly http: HttpClient) {}

Expand Down
7 changes: 7 additions & 0 deletions libs/shared/util-env/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# util-env

This library was generated with [Nx](https://nx.dev).

## Running unit tests

Run `nx test util-env` to execute the unit tests via [Jest](https://jestjs.io).
3 changes: 3 additions & 0 deletions libs/shared/util-env/eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const baseConfig = require('../../../eslint.config.js');

module.exports = [...baseConfig];
10 changes: 10 additions & 0 deletions libs/shared/util-env/jest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
export default {
displayName: 'util-env',
preset: '../../../jest.preset.js',
testEnvironment: 'node',
transform: {
'^.+\\.[tj]s$': ['ts-jest', { tsconfig: '<rootDir>/tsconfig.spec.json' }],
},
moduleFileExtensions: ['ts', 'js', 'html'],
coverageDirectory: '../../../coverage/libs/shared/util-env',
};
16 changes: 16 additions & 0 deletions libs/shared/util-env/project.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"name": "util-env",
"$schema": "../../../node_modules/nx/schemas/project-schema.json",
"sourceRoot": "libs/shared/util-env/src",
"projectType": "library",
"tags": [],
"targets": {
"test": {
"executor": "@nx/jest:jest",
"outputs": ["{workspaceRoot}/coverage/{projectRoot}"],
"options": {
"jestConfig": "libs/shared/util-env/jest.config.ts"
}
}
}
}
2 changes: 2 additions & 0 deletions libs/shared/util-env/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from './lib/env.development'
export * from './lib/env.interface'
6 changes: 6 additions & 0 deletions libs/shared/util-env/src/lib/env.development.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { IEnv } from './env.interface';

export const env: IEnv = {
production: false,
dataApiUrl: 'https://localhost:3000'
}
4 changes: 4 additions & 0 deletions libs/shared/util-env/src/lib/env.interface.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export interface IEnv {
production: boolean,
dataApiUrl: string
}
6 changes: 6 additions & 0 deletions libs/shared/util-env/src/lib/env.production.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { IEnv } from './env.interface';

export const env: IEnv = {
production: false,
dataApiUrl: 'instrumentrental-api-d2f7ahfvh8d2ahd0.westeurope-01.azurewebsites.net'
}
3 changes: 3 additions & 0 deletions libs/shared/util-env/src/lib/env.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export function env(): string {
return 'util-env';
}
16 changes: 16 additions & 0 deletions libs/shared/util-env/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"extends": "../../../tsconfig.base.json",
"compilerOptions": {
"module": "commonjs"
},
"files": [],
"include": [],
"references": [
{
"path": "./tsconfig.lib.json"
},
{
"path": "./tsconfig.spec.json"
}
]
}
11 changes: 11 additions & 0 deletions libs/shared/util-env/tsconfig.lib.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"module": "commonjs",
"outDir": "../../../dist/out-tsc",
"declaration": true,
"types": ["node"]
},
"exclude": ["jest.config.ts", "src/**/*.spec.ts", "src/**/*.test.ts"],
"include": ["src/**/*.ts"]
}
14 changes: 14 additions & 0 deletions libs/shared/util-env/tsconfig.spec.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"outDir": "../../../dist/out-tsc",
"module": "commonjs",
"types": ["jest", "node"]
},
"include": [
"jest.config.ts",
"src/**/*.test.ts",
"src/**/*.spec.ts",
"src/**/*.d.ts"
]
}
3 changes: 3 additions & 0 deletions tsconfig.base.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
"libs/backend/features/src/index.ts"
],
"@InstrumentRental/shared/api": ["libs/shared/api/src/index.ts"],
"@InstrumentRental/shared/util-env": [
"libs/shared/util-env/src/index.ts"
],
"@avans-nx-workshop/shared/api": ["libs/shared/api/src/index.ts"],
"@instrument-rental/common": ["libs/frontend/common/src/index.ts"],
"@instrument-rental/features": ["libs/frontend/features/src/index.ts"],
Expand Down

0 comments on commit 349b019

Please sign in to comment.