Added Roles, User Management, fixed bugs, added FlexTable component (should be renamed to GridTable), other table components and test code should be removed down the line, added admin function to fix broken data structures.

This commit is contained in:
2022-05-17 11:06:15 -07:00
parent 038c68f618
commit bc4b1c7256
58 changed files with 7001 additions and 838 deletions

13
server/DataCollection.js Normal file
View File

@@ -0,0 +1,13 @@
import {MongoInternals} from 'meteor/mongo';
import {Meteor} from 'meteor/meteor';
let uri = process.env.MONGO_URL2; //"mongodb://localhost:27017/avusd_data_collection";
//uri = "mongodb://localhost:27017/avusd_data_collection";
//console.log(uri);
let db2 = new MongoInternals.RemoteCollectionDriver(uri);
let collection = new Mongo.Collection("records", {_driver: db2});
Meteor.Records = collection;
// let results = collection.find({deviceId: "1e3e99ef-adf4-4aa2-8784-205bc60f0ce3"}).fetch();
// console.log(results);

90
server/logging.js Normal file
View File

@@ -0,0 +1,90 @@
import FileRotateTransport from "winston-daily-rotate-file";
import winston from "winston";
import moment from "moment";
import _ from 'underscore';
let production = (process.env.NODE_ENV === "production");
let logPath = process.env.LOG_PATH;
let fileTransport = logPath ? new FileRotateTransport({
format: winston.format.combine(
winston.format.simple(),
winston.format.printf((info) => {
return moment(info.timestamp).format('YYYY-MM-DD hh:mm:ss SSSS') + " " + info.message;
})
),
auditFile: "audit.json",
maxSize: '1m',
maxFiles: 20,
dirname: logPath,
filename: 'DistrictCentral-%DATE%.log',
dateFormat: "YYYY-MM-DD"
}) : null;
let consoleColorTransport = new winston.transports.Console({
format: winston.format.combine(
winston.format.cli()
),
});
let consoleTransport = new winston.transports.Console({
format: winston.format.combine(
winston.format.simple()
),
});
let transports = production ? (logPath ? [fileTransport] : [consoleTransport]) : (logPath ? [fileTransport, consoleColorTransport] : [consoleColorTransport]);
//let transports = [fileTransport, consoleTransport];
//TODO: Use GrayLog or SysLog and interface with a log server.
/* Use GrayLog2 Transport
const Graylog2 = require('winston-graylog2');
logger.add(new Graylog2(options));
*/
/* Use Syslog Transport
npm install winston-syslog
const winston = require('winston');
//
// Requiring `winston-syslog` will expose
// `winston.transports.Syslog`
//
require('winston-syslog').Syslog;
winston.add(new winston.transports.Syslog(options));
*/
// Setup the logger.
let logger = winston.createLogger({
level: production ? 'info' : 'silly',
// format: winston.format.combine(
// winston.format.timestamp({format: 'YYYY-MM-DD hh:mm:ss SSSS'})
// ),
format: winston.format(function(info) {
//Add a timestamp to the info structure.
info.timestamp = new Date();
return info;
})(),
defaultMeta: {app: 'DistrictCentral'},
transports: transports
});
let consoleLogOriginal = console.log;
// Override the log and error functions.
console.log = function(d) {
// For some reason Meteor requires the original console.log for the initial listening log output. If that isn't performed then Meteor never starts properly.
if(arguments.length === 1 && arguments[0] === 'LISTENING') {
return consoleLogOriginal.call(console, 'LISTENING');
}
else logger.log("debug", _.isObject(d) ? JSON.stringify(d) : d);
}
console.info = function(d) {
logger.log("info", _.isObject(d) ? JSON.stringify(d) : d);
}
console.warn = function(d) {
logger.log("warn", _.isObject(d) ? JSON.stringify(d) : d);
}
console.error = function(e) {
logger.log("error", e.stack || e);
}

View File

@@ -1,40 +1,35 @@
import './DataCollection.js';
import '../imports/api/';
import './google-oauth.js';
import '/imports/startup/accounts-config.js';
import './logging';
import url from 'url';
//import './google-oauth.js';
import connectRoute from 'connect-route';
/* Did not work at all.. not sure why.
let WebSocketServer = require("ws").Server;
//var wss = new WebSocketServer({ port: env.PORT });
let wss = new WebSocketServer({host: '192.168.3.101', port: 3001});
console.log("Starting WS");
wss.on("connection", function (ws) {
console.log("WS Open");
ws.on("message", function(data) {
console.log(data);
ws.send("Pong");
}).on("error", (err) => {
console.log(err);
})
}).on('error', (err) => {
console.error(err);
});
// const net = require('net');
//Some basic testing of detecting which mode the app is running under...
//
// const server = net.createServer((socket) => {
// socket.on('data', (data) => {
// console.log(data.toString());
// socket.write("Pong");
// });
// }).on('error', (err) => {
// console.error(err);
// });
// if(process.env.NODE_ENV === "development") {
// console.log("In Dev Mode");
// }
// else if(process.env.NODE_ENV === "production") {
// console.log("In Prod Mode");
// }
// else {
// console.log("No idea what mode we are in!");
// }
//TEST LOG OUTPUT...
// let obj = {test: 'abc'};
// console.log("Test Output");
// console.log(obj);
//
// try {
// throw Exception("Error!!");
// }
// catch(err) {
// console.error(err);
// }
*/