1 | /*
|
2 | ExpressJS for volebo.net
|
3 |
|
4 | Copyright (C) 2016-2017 Volebo <dev@volebo.net>
|
5 | Copyright (C) 2016-2017 Koryukov Maksim <maxkoryukov@gmail.com>
|
6 |
|
7 | This program is free software: you can redistribute it and/or modify
|
8 | it under the terms of the GNU General Public License as published by
|
9 | the Free Software Foundation, either version 3 of the License, or
|
10 | (at your option) any later version.
|
11 |
|
12 | This program is distributed in the hope that it will be useful,
|
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of
|
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
15 | GNU General Public License for more details.
|
16 |
|
17 | You should have received a copy of the GNU General Public License
|
18 | along with this program. If not, see <http://www.gnu.org/licenses/>.
|
19 | */
|
20 |
|
21 | ;
|
22 |
|
23 | const fs = require('fs');
|
24 |
|
25 | //const debug = require('debug')('volebo:express:config');
|
26 | const _ = require('lodash');
|
27 | const yaml = require('js-yaml');
|
28 |
|
29 | let config = function config(options) {
|
30 | if (_.isNil(options)) {
|
31 | options = {};
|
32 | }
|
33 |
|
34 | let def = {
|
35 | "server": {
|
36 | "host": "127.0.0.1",
|
37 | "port": 3000,
|
38 | "path": null
|
39 | },
|
40 |
|
41 | "debug": {
|
42 | "renderStack": false,
|
43 | "staticPath": "public",
|
44 | },
|
45 |
|
46 | "session": {
|
47 | "enabled": true,
|
48 | "name": "sessionId",
|
49 | "secret" : "DO NOT FORGET TO CHANGE!",
|
50 | "secure" : false,
|
51 | "domain": []
|
52 | },
|
53 |
|
54 | "auth": {
|
55 | "enabled": true,
|
56 | "session": true,
|
57 | },
|
58 |
|
59 | "proxy": {
|
60 | "list": ["loopback"]
|
61 | },
|
62 |
|
63 | "model": {
|
64 | "enabled": false,
|
65 |
|
66 | "db" : {
|
67 | "timezone" : "utc",
|
68 | "username" : "",
|
69 | "password" : "",
|
70 | "database" : "",
|
71 | "host" : "localhost",
|
72 | "benchmark": true
|
73 | },
|
74 | },
|
75 | };
|
76 |
|
77 | _.defaultsDeep(options, def);
|
78 |
|
79 | return options;
|
80 | }
|
81 |
|
82 | /**
|
83 | * Read object from JSON-file synchronously
|
84 | *
|
85 | * @param {path} filename - path to the file
|
86 | * @return {object}
|
87 | */
|
88 | config.readJson = function(filename) {
|
89 | return JSON.parse(fs.readFileSync(filename, 'utf8'));
|
90 | };
|
91 |
|
92 | /**
|
93 | * Read object from YAML-file synchronously
|
94 | *
|
95 | * @param {path} filename - path to the file
|
96 | * @return {object}
|
97 | */
|
98 | config.readYaml = function(filename) {
|
99 | return yaml.load(fs.readFileSync(filename, 'utf8'));
|
100 | };
|
101 |
|
102 | exports = module.exports = config;
|