Skip to content
Snippets Groups Projects
Commit 1b7ea337 authored by Markus Grigull's avatar Markus Grigull
Browse files

Replace configuration in server.js

parent e2ad9bc0
No related branches found
No related tags found
2 merge requests!10Resolve "Add dynamic configuration files",!9Resolve "Add dynamic configuration files"
This commit is part of merge request !9. Comments created here will be created in the context of that merge request.
/**
* File: config.js
* Author: Markus Grigull <mgrigull@eonerc.rwth-aachen.de>
* Date: 23.06.2016
*
* This file is part of VILLASweb-backend.
*
* VILLASweb-backend is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* VILLASweb-backend is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with VILLASweb-backend. If not, see <http://www.gnu.org/licenses/>.
******************************************************************************/
module.exports = {
publicDir: '../public',
development: {
databaseName: 'VILLAS',
databaseURL: 'mongodb://localhost:27017/',
amqpEndpoint: 'amqp://localhost',
amqpUpdateRate: 5,
port: 4000,
secret: 'longsecretislong',
logLevel: 'verbose', // possible values: error, warn, info, verbose or debug
admin: {
username: 'admin',
password: 'admin'
}
},
production: {
databaseName: 'VILLAS',
databaseURL: 'mongodb://database:27017/',
amqpEndpoint: 'amqp://rabbit',
amqpUpdateRate: 60,
port: 4000,
secret: 'longsecretislong',
logLevel: 'warn', // possible values: error, warn, info, verbose or debug
logFile: 'villasweb-backend_log.txt',
admin: {
username: 'admin',
password: 'admin'
}
}
};
......@@ -23,7 +23,7 @@
const _ = require('lodash');
const defaults = require('./default').default;
const defaults = require('./default');
const config = require('./' + (process.env.NODE_ENV || 'development'));
// merge configuration file with defaults
......
......@@ -29,6 +29,7 @@ var expressWinston = require('express-winston');
var git = require('git-rev-sync');
// local include
const config = require('./config/index');
var logger = require('./utils/logger');
var users = require('./routes/users');
var projects = require('./routes/projects');
......@@ -47,9 +48,6 @@ var User = require('./models/user');
// create application
var app = express();
// load configuration
var config = require('./config')[app.get('env')];
// configure logger
if (config.logLevel) {
logger.transports.console.level = config.logLevel;
......@@ -146,9 +144,9 @@ app.listen(config.port, function() {
});
// add admin account
if (config.admin) {
if (config.defaultAdmin) {
// check if admin account exists
User.findOne({ username: config.admin.username }, function(err, user) {
User.findOne({ username: 'admin' }, function(err, user) {
if (err) {
logger.error(err);
return;
......@@ -156,7 +154,7 @@ if (config.admin) {
if (!user) {
// create new admin user
var newUser = User({ username: config.admin.username, password: config.admin.password, role: 'admin' });
var newUser = User({ username: 'admin', password: 'admin', role: 'admin' });
newUser.save(function(err) {
if (err) {
logger.error(err);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment