UNPKG

2.19 kBJavaScriptView Raw
1/*
2ExpressJS for volebo.net
3
4Copyright (C) 2016-2017 Volebo <dev@volebo.net>
5Copyright (C) 2016-2017 Koryukov Maksim <maxkoryukov@gmail.com>
6
7This program is free software: you can redistribute it and/or modify
8it under the terms of the GNU General Public License as published by
9the Free Software Foundation, either version 3 of the License, or
10(at your option) any later version.
11
12This program is distributed in the hope that it will be useful,
13but WITHOUT ANY WARRANTY; without even the implied warranty of
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15GNU General Public License for more details.
16
17You should have received a copy of the GNU General Public License
18along with this program. If not, see <http://www.gnu.org/licenses/>.
19*/
20
21"use strict";
22
23const fs = require('fs');
24
25//const debug = require('debug')('volebo:express:config');
26const _ = require('lodash');
27const yaml = require('js-yaml');
28
29let 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 */
88config.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 */
98config.readYaml = function(filename) {
99 return yaml.load(fs.readFileSync(filename, 'utf8'));
100};
101
102exports = module.exports = config;