Mainflux.mainflux/server.js

43 lines
1.3 KiB
JavaScript
Raw Normal View History

2015-07-07 04:32:02 +08:00
// server.js
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);
2015-07-07 04:32:02 +08:00
// BASE SETUP
// =============================================================================
// call the packages we need
var express = require('express'); // call express
var app = express(); // define our app using express
var bodyParser = require('body-parser');
// MongoDB
var mongoose = require('mongoose');
2015-07-28 06:50:20 +08:00
// Docker MongoDB url
var docker_mongo_url = process.env.MAINFLUX_MONGODB_1_PORT_27017_TCP_ADDR
2015-07-07 04:32:02 +08:00
2015-07-28 06:50:20 +08:00
mongoose.connect(docker_mongo_url || config.db.path + ':' + config.db.port + '/' + config.db.name); // connect to our database
2015-07-07 04:32:02 +08:00
// configure app to use bodyParser()
// this will let us get the data from a POST
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 FOR OUR API
// =============================================================================
2015-07-27 05:37:22 +08:00
app.use('/status', require('./app/routes/status'));
app.use('/things', require('./app/routes/things'));
2015-07-07 04:32:02 +08:00
// START THE SERVER
// =============================================================================
app.listen(port);
console.log('Magic happens on port ' + port);