Ready to go

This commit is contained in:
Luke Berndt
2023-04-11 15:54:32 -04:00
parent 9eeeb0e839
commit 60944e4d4f
2 changed files with 32 additions and 19 deletions

View File

@@ -97,8 +97,19 @@ async function build_filter(filter_type, code, start_time, direction, shortName,
if (filter_type) {
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();
if (!group) {

View File

@@ -46,15 +46,26 @@ var port = process.env['MONGO_NODE_DRIVER_PORT'] != null ? process.env['MONGO_NO
var mongoUrl = 'mongodb://' + host + ':' + port + '/scanner';
const connect = () => {
mongoose.connect(mongoUrl).then((result) => { // Successfully connected
console.log("connected to Mongo");
})
.catch((err) => {
// Catch any potential error
console.log(mongoose.version);
console.log("Unable to connect to MongoDB. Error: " + err);
const connect = async () => {
// Demonstrate the readyState and on event emitters
console.log(mongoose.connection.readyState); //logs 0
mongoose.connection.on('connecting', () => {
console.log('Mongoose is connecting')
console.log(mongoose.connection.readyState); //logs 2
});
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();
@@ -162,9 +173,6 @@ function get_clients(req, res) {
/*------ CLIENTS ----------*/
app.get('/clients', get_clients);
app.get('/:shortName/clients', get_clients);
app.use(function (err, req, res, next) {
console.error("Caught an error");
console.error(err.stack);
@@ -232,12 +240,6 @@ function notify_clients(call) {
}
}
io.sockets.on('connection', function (client) {
clients[client.id] = { socket: client, active: false };
clients[client.id].timestamp = new Date();