@lenne.tech/nest-server 10.8.0 → 10.8.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/core/common/helpers/config.helper.d.ts +2 -1
- package/dist/core/common/helpers/config.helper.js +17 -2
- package/dist/core/common/helpers/config.helper.js.map +1 -1
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/core/common/helpers/config.helper.ts +23 -4
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lenne.tech/nest-server",
|
|
3
|
-
"version": "10.8.
|
|
3
|
+
"version": "10.8.2",
|
|
4
4
|
"description": "Modern, fast, powerful Node.js web framework in TypeScript based on Nest with a GraphQL API and a connection to MongoDB (or other databases).",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"node",
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import * as dotenv from 'dotenv';
|
|
2
|
+
import * as process from 'node:process';
|
|
2
3
|
import { join } from 'path';
|
|
3
4
|
|
|
4
5
|
import _ = require('lodash');
|
|
@@ -60,15 +61,21 @@ export function merge(obj: Record<string, any>, ...sources: any[]): any {
|
|
|
60
61
|
* @param options options for processing
|
|
61
62
|
* @param options.config config object with different environments as main keys (see config.env.ts) to merge environment configurations into (default: {})
|
|
62
63
|
* @param options.defaultEnv default environment to use if no NODE_ENV is set (default: 'local')
|
|
64
|
+
* @param options.envPath path to .env file (default: undefined => default of dotenv)
|
|
63
65
|
*/
|
|
64
|
-
export function getEnvironmentConfig(options: { config?: Record<string, any>; defaultEnv?: string }) {
|
|
65
|
-
const { config, defaultEnv } = {
|
|
66
|
+
export function getEnvironmentConfig(options: { config?: Record<string, any>; defaultEnv?: string; envPath?: string }) {
|
|
67
|
+
const { config, defaultEnv, envPath } = {
|
|
66
68
|
config: {},
|
|
67
69
|
defaultEnv: 'local',
|
|
68
70
|
...options,
|
|
69
71
|
};
|
|
70
72
|
|
|
71
|
-
|
|
73
|
+
if (envPath) {
|
|
74
|
+
dotenv.config({ path: envPath });
|
|
75
|
+
} else {
|
|
76
|
+
dotenv.config();
|
|
77
|
+
}
|
|
78
|
+
|
|
72
79
|
const env = process.env['NODE' + '_ENV'] || defaultEnv;
|
|
73
80
|
const envConfig = config[env] || config.local || {};
|
|
74
81
|
|
|
@@ -138,7 +145,10 @@ export function getEnvironmentConfig(options: { config?: Record<string, any>; de
|
|
|
138
145
|
/**
|
|
139
146
|
* Get environment object from environment variables
|
|
140
147
|
*/
|
|
141
|
-
export function getEnvironmentObject(options?: {
|
|
148
|
+
export function getEnvironmentObject(options?: {
|
|
149
|
+
prefix?: string;
|
|
150
|
+
processEnv?: Record<string, boolean | number | string>;
|
|
151
|
+
}) {
|
|
142
152
|
const config = {
|
|
143
153
|
prefix: 'NSC__',
|
|
144
154
|
processEnv: process.env,
|
|
@@ -165,6 +175,15 @@ export function getEnvironmentObject(options?: { prefix?: string; processEnv?: R
|
|
|
165
175
|
for (let i = 0; i < path.length; i++) {
|
|
166
176
|
const segment = path[i];
|
|
167
177
|
if (i === path.length - 1) {
|
|
178
|
+
// value preparation
|
|
179
|
+
if (value === 'true') {
|
|
180
|
+
value = true;
|
|
181
|
+
} else if (value === 'false') {
|
|
182
|
+
value = false;
|
|
183
|
+
} else if (!isNaN(Number(value))) {
|
|
184
|
+
value = Number(value);
|
|
185
|
+
}
|
|
186
|
+
|
|
168
187
|
current[segment] = value;
|
|
169
188
|
} else {
|
|
170
189
|
current = current[segment] = current[segment] || {};
|