Initial check in; All but the history pages working.
This commit is contained in:
36
server/CheckEnvironment.js
Normal file
36
server/CheckEnvironment.js
Normal file
@@ -0,0 +1,36 @@
|
||||
console.log("Checking Environment...");
|
||||
|
||||
if(!process.env.MONGO_URL) {
|
||||
console.error("Must provide the MONGO_URL environment variable point to the district central's main database. Should be of the format: `mongodb://localhost:27017/DatabaseName` or `mongodb://user_name:password@host.domain.com,host2.domain.com,host3.domain.com/DatabaseName?replicaSet=set_name`.")
|
||||
process.exit(0);
|
||||
}
|
||||
|
||||
if(!process.env.MONGO_URL2) {
|
||||
console.error("Must provide the MONGO_URL2 environment variable pointing to the chromebook data collection dataset. Should be of the format: `mongodb://localhost:27017/DatabaseName` or `mongodb://user_name:password@host.domain.com,host2.domain.com,host3.domain.com/DatabaseName?replicaSet=set_name`.")
|
||||
process.exit(0);
|
||||
}
|
||||
|
||||
try {
|
||||
let settings = Assets.getText('settings.json');
|
||||
}
|
||||
catch(e) {
|
||||
console.error("Must have a /private/settings.json file with the following format:");
|
||||
console.error(`
|
||||
{
|
||||
"google": {
|
||||
"clientId": "xxxxxxxxxxxxxxxxxxx.apps.googleusercontent.com",
|
||||
"secret": "xxxxxxxxxxxxxxxxxxx",
|
||||
"loginStyle": "redirect",
|
||||
"scope": [
|
||||
"email",
|
||||
"https://www.googleapis.com/auth/plus.login",
|
||||
"https://www.googleapis.com/auth/contacts.readonly"
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
`);
|
||||
process.exit(0);
|
||||
}
|
||||
|
||||
console.log("Environment Checking Complete.")
|
||||
17
server/DataCollection.js
Normal file
17
server/DataCollection.js
Normal file
@@ -0,0 +1,17 @@
|
||||
import {MongoInternals} from 'meteor/mongo';
|
||||
import {Meteor} from 'meteor/meteor';
|
||||
|
||||
console.log("Setting up data collection database connection...");
|
||||
|
||||
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);
|
||||
|
||||
console.log("Database connection setup.")
|
||||
54
server/google-oauth.js
Normal file
54
server/google-oauth.js
Normal file
@@ -0,0 +1,54 @@
|
||||
/**
|
||||
* Google cloud platform: https://console.developers.google.com/apis/dashboard
|
||||
* Setup a OAuth consent screen, then setup OAuth credentials.
|
||||
* Loads the information from the /private/settings.json file.
|
||||
*/
|
||||
|
||||
console.log("Setting up Google OAuth...");
|
||||
|
||||
try {
|
||||
let settings = Assets.getText('settings.json');
|
||||
|
||||
if(settings) {
|
||||
try {
|
||||
settings = JSON.parse(settings);
|
||||
}
|
||||
catch(err) {
|
||||
console.error("Failed to load the /private/settings.json file as a JSON object.");
|
||||
console.error(err);
|
||||
settings = null;
|
||||
}
|
||||
}
|
||||
|
||||
if (settings) {
|
||||
ServiceConfiguration.configurations.upsert({
|
||||
service: "google"
|
||||
}, {
|
||||
$set: {
|
||||
loginStyle: settings.google.loginStyle,
|
||||
clientId: settings.google.clientId,
|
||||
secret: settings.google.secret
|
||||
}
|
||||
}
|
||||
);
|
||||
} else {
|
||||
console.log("Error: No settings file.");
|
||||
}
|
||||
} catch (err) {
|
||||
console.log(err);
|
||||
}
|
||||
|
||||
/*
|
||||
ServiceConfiguration.configurations.upsert(
|
||||
{ service: 'google' },
|
||||
{
|
||||
$set: {
|
||||
clientId: '651343079360-hm5vvji109lphnavft8vej5pp1ruek5q.apps.googleusercontent.com',
|
||||
loginStyle: 'popup',
|
||||
secret: 'VAQFr6UBkZ0ZMQJ7tb471BmW'
|
||||
}
|
||||
}
|
||||
);
|
||||
*/
|
||||
|
||||
console.log("Finished OAuth setup.")
|
||||
94
server/logging.js
Normal file
94
server/logging.js
Normal file
@@ -0,0 +1,94 @@
|
||||
import FileRotateTransport from "winston-daily-rotate-file";
|
||||
import winston from "winston";
|
||||
import moment from "moment";
|
||||
import _ from 'underscore';
|
||||
|
||||
// console.log("Setting up logging....");
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
// console.log("Logger setup.");
|
||||
35
server/main.js
Normal file
35
server/main.js
Normal file
@@ -0,0 +1,35 @@
|
||||
import './CheckEnvironment.js';
|
||||
import './DataCollection.js';
|
||||
import '../imports/api/';
|
||||
import './google-oauth.js';
|
||||
import '/imports/startup/accounts-config.js';
|
||||
import './logging';
|
||||
|
||||
|
||||
|
||||
|
||||
//Some basic testing of detecting which mode the app is running under...
|
||||
//
|
||||
// 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);
|
||||
// }
|
||||
|
||||
Reference in New Issue
Block a user