Skip to content
This repository was archived by the owner on Nov 15, 2024. It is now read-only.

Commit fb804ba

Browse files
committed
longstanding project to slowly put some comments into my source code...
1 parent ce704ed commit fb804ba

File tree

122 files changed

+1063
-477
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

122 files changed

+1063
-477
lines changed

api_server/README.pubnub

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ We currently have a demo subscription
33
https://admin.pubnub.com
44

55
6-
password: pkt4Rocks
6+
password: CS!R0cks
77

88
publish key: pub-c-b65a2340-6854-4bf2-9ab4-ed971aea9dd4
99
subscribe key: sub-c-12519fba-c8a0-11e6-8164-0619f8945a4f
10-
secret: sec-c-NmFkMzAyM2YtMGI2MC00ZDU2LWFmZDgtMTE1Y2FmODQ5YTEy
10+
secret: sec-c-NmFkMzAyM2YtMGI2MC00ZDU2LWFmZDgtMTE1Y2FmODQ5YTEy

api_server/README.quick_test

Lines changed: 0 additions & 33 deletions
This file was deleted.

api_server/bin/api_server.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
11
#!/usr/bin/env node
2+
3+
// Main executable for running the CodeStream API Server
4+
//
5+
// We'll load a bunch of configurations and then use a "generic" API server to do most of the work
6+
27
'use strict';
38

4-
var APICluster = require(process.env.CS_API_TOP + '/lib/api_server/api_cluster.js');
9+
var APICluster = require(process.env.CS_API_TOP + '/lib/api_server/api_cluster.js'); // this is the real meat of the API server
10+
11+
// load configurations
512
const ConfigDirectory = process.env.CS_API_TOP + '/config';
613
const ModuleDirectory = process.env.CS_API_TOP + '/services/api/modules';
714
const ApiConfig = require(ConfigDirectory + '/api.js');
@@ -15,12 +22,15 @@ const Limits = require(ConfigDirectory + '/limits.js');
1522
const Version = require(ConfigDirectory + '/version.js');
1623
const SimpleFileLogger = require(process.env.CS_API_TOP + '/lib/util/simple_file_logger');
1724

25+
// establish our logger
1826
var Logger = new SimpleFileLogger(LoggerConfig);
1927

2028
if (MongoConfig.queryLogging) {
29+
// we maintain a separate log file for mongo queries
2130
Object.assign(MongoConfig.queryLogging, LoggerConfig, MongoConfig.queryLogging);
2231
}
2332

33+
// establish our data collections
2434
const DataCollections = {
2535
users: require(ModuleDirectory + '/users/user'),
2636
companies: require(ModuleDirectory + '/companies/company'),
@@ -33,6 +43,7 @@ const DataCollections = {
3343
};
3444
const MongoCollections = Object.keys(DataCollections);
3545

46+
// invoke a node cluster master with our configurations provided
3647
var MyAPICluster = new APICluster({
3748
moduleDirectory: ModuleDirectory,
3849
api: ApiConfig,
@@ -51,6 +62,7 @@ var MyAPICluster = new APICluster({
5162
dataCollections: DataCollections
5263
}, Logger);
5364

65+
// start up the master, this will launch workers to really get down to work
5466
MyAPICluster.start((error) => {
5567
if (error) {
5668
console.error('Failed to start: ' + error);

api_server/config/api.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1+
// general api server configuration
2+
13
'use strict';
24

35
module.exports = {
4-
confirmationNotRequired: process.env.CS_API_CONFIRMATION_NOT_REQUIRED
6+
confirmationNotRequired: process.env.CS_API_CONFIRMATION_NOT_REQUIRED // avoid the email configuration by setting this env var
57
};

api_server/config/api_test.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1+
// configuration for running api server unit tests
2+
13
'use strict';
24

35
module.exports = {
4-
api: {
6+
api: { // where is the api server running?
57
host: process.env.CS_API_HOST,
68
port: process.env.CS_API_PORT
79
},
8-
mongo: {
10+
mongo: { // where is mongo running?
911
host: process.env.CS_API_MONGO_HOST,
1012
port: process.env.CS_API_MONGO_PORT,
1113
database: process.env.CS_API_MONGO_DATABASE

api_server/config/email.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1+
// email configuration
2+
13
'use strict';
24

35
module.exports = {
4-
sendgrid: {
6+
sendgrid: { // sendgrid credentials
57
url: '/v3/mail/send',
68
apiKey: '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',
7-
emailTo: process.env.CS_API_EMAIL_TO
9+
emailTo: process.env.CS_API_EMAIL_TO // redirect emails to this address, for safe testing
810
},
9-
senderEmail: '[email protected]',
10-
confirmationEmailTemplateId: '300934c5-3a9c-46f8-a905-b801c23439ab',
11+
senderEmail: '[email protected]', // we'll send emails from this address
12+
confirmationEmailTemplateId: '300934c5-3a9c-46f8-a905-b801c23439ab', // template to use for confirmation emails
1113
};

api_server/config/express.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
1+
// express js configuration
2+
13
'use strict';
24

35
module.exports = {
46
host: process.env.CS_API_HOST,
57
port: process.env.CS_API_PORT,
6-
https: {
8+
https: { // https key/cert
79
keyfile: process.env.CS_API_SSL_KEYFILE,
810
certfile: process.env.CS_API_SSL_CERTFILE,
911
cafile: process.env.CS_API_SSL_CAFILE
1012
},
11-
ignoreHttps: process.env.CS_API_IGNORE_HTTPS
13+
ignoreHttps: process.env.CS_API_IGNORE_HTTPS // run on http instead of https, for testing only
1214
};

api_server/config/limits.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1+
// defines various limits
2+
13
'use strict';
24

35
module.exports = {
4-
maxPostsPerRequest: 100,
5-
maxStreamsPerRequest: 100,
6-
maxMarkersPerRequest: 100
6+
maxPostsPerRequest: 100, // never serve more than this many posts in a page
7+
maxStreamsPerRequest: 100, // never serve more than this many streams in a page
8+
maxMarkersPerRequest: 100 // never serve more than this many markers in a page (not currently used)
79
};

api_server/config/logger.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1+
// logger configuration
2+
13
'use strict';
24

35
module.exports = {
4-
directory: process.env.CS_API_LOG_DIRECTORY,
5-
basename: 'api',
6-
retentionPeriod: 30 * 24 * 60 * 60 * 1000,
7-
consoleOk: process.env.CS_API_LOG_CONSOLE_OK,
8-
debugOk: process.env.CS_API_LOG_DEBUG
6+
directory: process.env.CS_API_LOG_DIRECTORY, // put log files in this directory
7+
basename: 'api', // use this for the basename of the log file
8+
retentionPeriod: 30 * 24 * 60 * 60 * 1000, // retain log files for this many milliseconds
9+
consoleOk: process.env.CS_API_LOG_CONSOLE_OK, // also output to the console
10+
debugOk: process.env.CS_API_LOG_DEBUG // output debug messages, for special debugging
911
};

api_server/config/mongo.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
1+
// mongo configuration
2+
13
'use strict';
24

35
module.exports = {
46
host: process.env.CS_API_MONGO_HOST,
57
port: process.env.CS_API_MONGO_PORT,
68
database: process.env.CS_API_MONGO_DATABASE,
7-
queryLogging: {
9+
queryLogging: { // we write a separate log file for mongo queries, and for slow and "really slow" queries so we can look for problems
810
basename: 'mongo-query',
911
slowBasename: 'slow-mongo-query',
10-
slowThreshold: 100,
12+
slowThreshold: 100, // queries that take longer than this go to the slow query log
1113
reallySlowBasename: 'really-slow-mongo-query',
12-
reallySlowThreshold: 1000
14+
reallySlowThreshold: 1000 // queries that take longer than this go to the "really slow" query log
1315
}
1416
};

0 commit comments

Comments
 (0)