1
0
mirror of https://github.com/mainflux/mainflux.git synced 2025-04-27 13:48:49 +08:00

Move config.js in root dir, add MQTT and HTTP conf

Signed-off-by: Drasko DRASKOVIC <drasko.draskovic@gmail.com>
This commit is contained in:
Drasko DRASKOVIC 2016-04-27 23:01:30 +02:00
parent eff9fd2411
commit 8fee81d8bc
3 changed files with 60 additions and 17 deletions

View File

@ -1,4 +1,4 @@
var config = require('../config/config');
var config = require('../config');
/**
* MONGO DB
@ -14,7 +14,7 @@ var dbUrl = '';
if (dockerMongo && dockerMongo == '/mainflux-api/mongodb') {
dbUrl = 'mongodb://' + process.env.MONGODB_PORT_27017_TCP_ADDR + ':' + process.env.MONGODB_PORT_27017_TCP_PORT + '/' + config.db.name;
} else {
dbUrl = 'mongodb://' + config.db.addr + ':' + config.db.port + '/' + config.db.name;
dbUrl = 'mongodb://' + config.db.host + ':' + config.db.port + '/' + config.db.name;
}
var db = mongojs(dbUrl);

View File

@ -1,44 +1,36 @@
var restify = require('restify');
var config = require('../config/config');
var config = require('../config');
var devicesController = require('./controllers/devices');
var statusController = require('./controllers/status');
var rateLimit = restify.throttle({
burst: config.limiter.defaultBurstRate,
rate: config.limiter.defaultRatePerSec,
ip: true
});
function routes(api) {
/**
* /STATUS
*/
api.get('/status', rateLimit, statusController.getStatus);
api.get('/status', statusController.getStatus);
/**
* /DEVICES
*/
/** Create a device (accessed at POST http://localhost:8080/devices) */
api.post('/devices', rateLimit, devicesController.createDevice);
api.post('/devices', devicesController.createDevice);
/** Get all the devices (accessed at GET http://localhost:8080/devices) */
api.get('/devices', rateLimit, devicesController.getAllDevices);
api.get('/devices', devicesController.getAllDevices);
/**
* /devices/:device_id
* N.B. Colon (`:`) is needed because of Express `req.params`: http://expressjs.com/api.html#req.params
*/
/** Get the device with given id (accessed at GET http://localhost:8080/devices/:device_id) */
api.get('/devices/:device_id', rateLimit, devicesController.getDevice)
api.get('/devices/:device_id', devicesController.getDevice)
/** Update the device with given id (accessed at PUT http://localhost:8080/devices/:device_id) */
api.put('/devices/:device_id', rateLimit, devicesController.updateDevice)
api.put('/devices/:device_id', devicesController.updateDevice)
/** Delete the device with given id (accessed at DELETE http://localhost:8080/devices/:device_id) */
api.del('/devices/:device_id', rateLimit, devicesController.deleteDevice);
api.del('/devices/:device_id', devicesController.deleteDevice);
}
module.exports = routes;

51
config.js Normal file
View File

@ -0,0 +1,51 @@
/**
* 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.
*/
var mosca = require('mosca');
var config = {};
/**
* HTTP
*/
config.http = {
message : 'We are in development',
port : 7070,
version: 0.1
}
/**
* MongoDB
*/
config.db = {
host : 'localhost',
port : 27017,
name : 'test'
}
/**
* Mosca
*/
var moscaBackend = {
type: 'redis',
redis: require('redis'),
db: 7,
port: 6379,
return_buffers: true, // to handle binary payloads
host: "localhost"
}
config.mosca = {
port: 1883,
backend: moscaBackend,
persistence: {
factory: mosca.persistence.Redis
}
}
module.exports = config;