Updated environment.ts and workflow
Some checks failed
Setup testing environment and test the code / build (push) Has been cancelled
Some checks failed
Setup testing environment and test the code / build (push) Has been cancelled
This commit is contained in:
2
.env.example
Normal file
2
.env.example
Normal file
@@ -0,0 +1,2 @@
|
||||
API_URL=https://api.chatenium.hu
|
||||
CDN_URL=https://cdn.chatenium.hu
|
||||
@@ -47,4 +47,7 @@ jobs:
|
||||
- name: Run Vitest
|
||||
run: |
|
||||
npm install
|
||||
npm test
|
||||
npm test
|
||||
env:
|
||||
API_URL: http://api:3000
|
||||
CDN_URL: http://cdn:4000
|
||||
5
.gitignore
vendored
5
.gitignore
vendored
@@ -10,4 +10,7 @@ yarn-error.log*
|
||||
|
||||
.vscode/*
|
||||
.idea/*
|
||||
.DS_Store
|
||||
.DS_Store
|
||||
.env
|
||||
.env.*
|
||||
!.env.example
|
||||
31
package-lock.json
generated
31
package-lock.json
generated
@@ -10,10 +10,12 @@
|
||||
"dependencies": {
|
||||
"@faker-js/faker": "^10.4.0",
|
||||
"axios": "^1.14.0",
|
||||
"dotenv": "^17.4.0",
|
||||
"msw": "^2.12.14",
|
||||
"uuid": "^13.0.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/node": "^25.5.2",
|
||||
"typescript": "^5.5.3",
|
||||
"vitest": "^4.1.2"
|
||||
}
|
||||
@@ -534,6 +536,16 @@
|
||||
"dev": true,
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/@types/node": {
|
||||
"version": "25.5.2",
|
||||
"resolved": "https://registry.npmjs.org/@types/node/-/node-25.5.2.tgz",
|
||||
"integrity": "sha512-tO4ZIRKNC+MDWV4qKVZe3Ql/woTnmHDr5JD8UI5hn2pwBrHEwOEMZK7WlNb5RKB6EoJ02gwmQS9OrjuFnZYdpg==",
|
||||
"devOptional": true,
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"undici-types": "~7.18.0"
|
||||
}
|
||||
},
|
||||
"node_modules/@types/statuses": {
|
||||
"version": "2.0.6",
|
||||
"resolved": "https://registry.npmjs.org/@types/statuses/-/statuses-2.0.6.tgz",
|
||||
@@ -836,6 +848,18 @@
|
||||
"node": ">=8"
|
||||
}
|
||||
},
|
||||
"node_modules/dotenv": {
|
||||
"version": "17.4.0",
|
||||
"resolved": "https://registry.npmjs.org/dotenv/-/dotenv-17.4.0.tgz",
|
||||
"integrity": "sha512-kCKF62fwtzwYm0IGBNjRUjtJgMfGapII+FslMHIjMR5KTnwEmBmWLDRSnc3XSNP8bNy34tekgQyDT0hr7pERRQ==",
|
||||
"license": "BSD-2-Clause",
|
||||
"engines": {
|
||||
"node": ">=12"
|
||||
},
|
||||
"funding": {
|
||||
"url": "https://dotenvx.com"
|
||||
}
|
||||
},
|
||||
"node_modules/dunder-proto": {
|
||||
"version": "1.0.1",
|
||||
"resolved": "https://registry.npmjs.org/dunder-proto/-/dunder-proto-1.0.1.tgz",
|
||||
@@ -1858,6 +1882,13 @@
|
||||
"node": ">=14.17"
|
||||
}
|
||||
},
|
||||
"node_modules/undici-types": {
|
||||
"version": "7.18.2",
|
||||
"resolved": "https://registry.npmjs.org/undici-types/-/undici-types-7.18.2.tgz",
|
||||
"integrity": "sha512-AsuCzffGHJybSaRrmr5eHr81mwJU3kjw6M+uprWvCXiNeN9SOGwQ3Jn8jb8m3Z6izVgknn1R0FTCEAP2QrLY/w==",
|
||||
"devOptional": true,
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/until-async": {
|
||||
"version": "3.0.2",
|
||||
"resolved": "https://registry.npmjs.org/until-async/-/until-async-3.0.2.tgz",
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
"test:watch": "vitest"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/node": "^25.5.2",
|
||||
"typescript": "^5.5.3",
|
||||
"vitest": "^4.1.2"
|
||||
},
|
||||
@@ -18,6 +19,7 @@
|
||||
"dependencies": {
|
||||
"@faker-js/faker": "^10.4.0",
|
||||
"axios": "^1.14.0",
|
||||
"dotenv": "^17.4.0",
|
||||
"msw": "^2.12.14",
|
||||
"uuid": "^13.0.0"
|
||||
}
|
||||
|
||||
@@ -3,19 +3,40 @@ export interface SDKConfig {
|
||||
cdnUrl: string;
|
||||
}
|
||||
|
||||
const DefaultEnvironment: SDKConfig = {
|
||||
apiUrl: "https://api.chatenium.hu",
|
||||
cdnUrl: "https://cdn.chatenium.hu",
|
||||
const isNode =
|
||||
typeof process !== 'undefined' &&
|
||||
typeof process.versions !== 'undefined' &&
|
||||
typeof process.versions.node !== 'undefined';
|
||||
|
||||
if (isNode) {
|
||||
try {
|
||||
require('dotenv').config();
|
||||
} catch { }
|
||||
}
|
||||
|
||||
let currentConfig = {...DefaultEnvironment}
|
||||
const getEnv = (key: string): string | undefined => {
|
||||
if (!isNode) return undefined;
|
||||
return process.env?.[key];
|
||||
};
|
||||
|
||||
const DefaultEnvironment: SDKConfig = {
|
||||
apiUrl: getEnv('API_URL') ?? "https://api.chatenium.hu",
|
||||
cdnUrl: getEnv('CDN_URL') ?? "https://cdn.chatenium.hu",
|
||||
};
|
||||
|
||||
let currentConfig: SDKConfig = { ...DefaultEnvironment };
|
||||
|
||||
export const environment = {
|
||||
get: () => currentConfig,
|
||||
overwrite: (newConfig: Partial<SDKConfig>) => {
|
||||
get(): SDKConfig {
|
||||
return { ...currentConfig };
|
||||
},
|
||||
overwrite(newConfig: Partial<SDKConfig>): void {
|
||||
currentConfig = {
|
||||
...currentConfig,
|
||||
...newConfig,
|
||||
};
|
||||
},
|
||||
}
|
||||
reset(): void {
|
||||
currentConfig = { ...DefaultEnvironment };
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user