Mainflux.mainflux/server.js

61 lines
1.4 KiB
JavaScript
Raw Normal View History

/**
* Copyright (c) Mainflux
*
* Mainflux server is licensed under an Apache license, version 2.0 license.
* All rights not explicitly granted in the Apache license, version 2.0 are reserved.
* See the included LICENSE file for more details.
*/
2015-07-07 04:32:02 +08:00
2015-07-27 05:37:22 +08:00
/**
* Extrenal configs are kept in the config.js file on the same level
*/
var config = require('./config/config');
console.log(config.message);
/**
* SETUP
*/
2015-07-07 04:32:02 +08:00
var express = require('express'); // call express
var app = express(); // define our app using express
var bodyParser = require('body-parser');
/** MongoDB */
2015-07-07 04:32:02 +08:00
var mongoose = require('mongoose');
/** Docker MongoDB url */
var docker_mongo_url = process.env.MAINFLUX_MONGODB_1_PORT_27017_TCP_ADDR
2015-07-07 04:32:02 +08:00
/** Connect to DB */
mongoose.connect(docker_mongo_url || config.db.path + ':' + config.db.port + '/' + config.db.name);
2015-07-07 04:32:02 +08:00
/** Configure app to use bodyParser() */
2015-07-07 04:32:02 +08:00
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());
2015-07-27 05:37:22 +08:00
var port = process.env.PORT || config.port; // set our port
2015-07-07 04:32:02 +08:00
/**
* ROUTES
*/
2015-07-27 05:37:22 +08:00
app.use('/status', require('./app/routes/status'));
2015-09-24 04:45:15 +08:00
app.use('/devices', require('./app/routes/devices'));
app.use('/users', require('./app/routes/users'));
app.use('/sessions', require('./app/routes/sessions'));
2015-07-07 04:32:02 +08:00
/**
* SERVER START
*/
2015-07-07 04:32:02 +08:00
app.listen(port);
console.log('Magic happens on port ' + port);
/**
* Export app for testing
*/
module.exports = app;