1 | "use strict";
|
2 | var __importDefault = (this && this.__importDefault) || function (mod) {
|
3 | return (mod && mod.__esModule) ? mod : { "default": mod };
|
4 | };
|
5 | Object.defineProperty(exports, "__esModule", { value: true });
|
6 | const debug_1 = __importDefault(require("debug"));
|
7 | const path_1 = __importDefault(require("path"));
|
8 | const config_1 = __importDefault(require("config"));
|
9 | const debug = debug_1.default('@feathersjs/configuration');
|
10 | const separator = path_1.default.sep;
|
11 | function init() {
|
12 | return (app) => {
|
13 | const convert = (current) => {
|
14 | const result = Array.isArray(current) ? [] : {};
|
15 | Object.keys(current).forEach(name => {
|
16 | let value = current[name];
|
17 | if (typeof value === 'object' && value !== null) {
|
18 | value = convert(value);
|
19 | }
|
20 | if (typeof value === 'string') {
|
21 | if (value.indexOf('\\') === 0) {
|
22 | value = value.replace('\\', '');
|
23 | }
|
24 | else {
|
25 | if (process.env[value]) {
|
26 | value = process.env[value];
|
27 | }
|
28 | if (value.indexOf('./') === 0 || value.indexOf('../') === 0) {
|
29 |
|
30 | value = path_1.default.resolve(path_1.default.join(config_1.default.util.getEnv('NODE_CONFIG_DIR')), value.replace(/\//g, separator));
|
31 | }
|
32 | }
|
33 | }
|
34 | result[name] = value;
|
35 | });
|
36 | return result;
|
37 | };
|
38 | const env = config_1.default.util.getEnv('NODE_ENV');
|
39 | const conf = convert(config_1.default);
|
40 | if (!app) {
|
41 | return conf;
|
42 | }
|
43 | debug(`Initializing configuration for ${env} environment`);
|
44 | Object.keys(conf).forEach(name => {
|
45 | const value = conf[name];
|
46 | debug(`Setting ${name} configuration value to`, value);
|
47 | app.set(name, value);
|
48 | });
|
49 | return conf;
|
50 | };
|
51 | }
|
52 | exports.default = init;
|
53 | if (typeof module !== 'undefined') {
|
54 | module.exports = Object.assign(init, module.exports);
|
55 | }
|
56 |
|
\ | No newline at end of file |