mirror of
https://github.com/openmhz/trunk-server.git
synced 2026-11-14 01:37:48 -05:00
Ready to go
This commit is contained in:
@@ -97,8 +97,19 @@ async function build_filter(filter_type, code, start_time, direction, shortName,
|
|||||||
|
|
||||||
if (filter_type) {
|
if (filter_type) {
|
||||||
if ((filter_type == "group") && code && (code.indexOf(',') == -1)) {
|
if ((filter_type == "group") && code && (code.indexOf(',') == -1)) {
|
||||||
|
let o_id
|
||||||
|
try {
|
||||||
|
o_id = ObjectId.createFromHexString(code);
|
||||||
|
} catch (err) {
|
||||||
|
console.warn("[" + shortName + "] Error - build_filter() group ObjectId is invalid " + err + " id: " + code);
|
||||||
|
res.contentType('json');
|
||||||
|
res.status(500);
|
||||||
|
res.send(JSON.stringify({
|
||||||
|
error: err,
|
||||||
|
"_id": objectId
|
||||||
|
}));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const group = await Group.findOne({ 'shortName': shortName, '_id': ObjectId.createFromHexString(code)}).exec();
|
const group = await Group.findOne({ 'shortName': shortName, '_id': ObjectId.createFromHexString(code)}).exec();
|
||||||
if (!group) {
|
if (!group) {
|
||||||
|
|||||||
@@ -46,15 +46,26 @@ var port = process.env['MONGO_NODE_DRIVER_PORT'] != null ? process.env['MONGO_NO
|
|||||||
var mongoUrl = 'mongodb://' + host + ':' + port + '/scanner';
|
var mongoUrl = 'mongodb://' + host + ':' + port + '/scanner';
|
||||||
|
|
||||||
|
|
||||||
const connect = () => {
|
const connect = async () => {
|
||||||
mongoose.connect(mongoUrl).then((result) => { // Successfully connected
|
// Demonstrate the readyState and on event emitters
|
||||||
console.log("connected to Mongo");
|
console.log(mongoose.connection.readyState); //logs 0
|
||||||
})
|
mongoose.connection.on('connecting', () => {
|
||||||
.catch((err) => {
|
console.log('Mongoose is connecting')
|
||||||
// Catch any potential error
|
console.log(mongoose.connection.readyState); //logs 2
|
||||||
console.log(mongoose.version);
|
|
||||||
console.log("Unable to connect to MongoDB. Error: " + err);
|
|
||||||
});
|
});
|
||||||
|
mongoose.connection.on('connected', () => {
|
||||||
|
console.log('Mongoose is connected');
|
||||||
|
console.log(mongoose.connection.readyState); //logs 1
|
||||||
|
});
|
||||||
|
mongoose.connection.on('disconnecting', () => {
|
||||||
|
console.log('Mongoose is disconnecting');
|
||||||
|
console.log(mongoose.connection.readyState); // logs 3
|
||||||
|
});
|
||||||
|
|
||||||
|
// Connect to a MongoDB server running on 'localhost:27017' and use the
|
||||||
|
// 'test' database.
|
||||||
|
await mongoose.connect(mongoUrl, { useNewUrlParser: true, useUnifiedTopology: true });
|
||||||
|
console.log("All Done");
|
||||||
}
|
}
|
||||||
connect();
|
connect();
|
||||||
|
|
||||||
@@ -162,9 +173,6 @@ function get_clients(req, res) {
|
|||||||
/*------ CLIENTS ----------*/
|
/*------ CLIENTS ----------*/
|
||||||
app.get('/clients', get_clients);
|
app.get('/clients', get_clients);
|
||||||
app.get('/:shortName/clients', get_clients);
|
app.get('/:shortName/clients', get_clients);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
app.use(function (err, req, res, next) {
|
app.use(function (err, req, res, next) {
|
||||||
console.error("Caught an error");
|
console.error("Caught an error");
|
||||||
console.error(err.stack);
|
console.error(err.stack);
|
||||||
@@ -232,12 +240,6 @@ function notify_clients(call) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
io.sockets.on('connection', function (client) {
|
io.sockets.on('connection', function (client) {
|
||||||
clients[client.id] = { socket: client, active: false };
|
clients[client.id] = { socket: client, active: false };
|
||||||
clients[client.id].timestamp = new Date();
|
clients[client.id].timestamp = new Date();
|
||||||
|
|||||||
Reference in New Issue
Block a user