Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Setup JSDoc #16

Merged
merged 20 commits into from
Dec 30, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 55 additions & 0 deletions .env_sample.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,69 @@
module.exports = {
env_development: {
/**
* @const NODE_ENV
* @description Node environment mode
* @global
* @type {String}
*/
NODE_ENV: 'development',

/**
* @const PORT
* @description Server port
* @global
* @type {Number}
*/
PORT: 3000,

/**
* @const SESSION_SECRET
* @description MongoDB store's session secret
* @global
* @type {String}
*/
SESSION_SECRET: 'RANDOM-SESSION-SECRET',

/**
* @const SESSION_KEY
* @description MongoDB store's session key
* @global
* @type {String}
*/
SESSION_KEY: 'RANDOM-SESSION-KEY',

/**
* @const MONGO_SESSION_URL
* @description MongoDB session table access URL
* @global
* @type {String}
*/
MONGO_SESSION_URL:
'mongodb+srv://USERNAME:PASSWORD@PROJECT-ID.CLOUD-PROVIDER.mongodb.net/DATABASE?retryWrites=true&w=majority',

/**
* @const MONGO_APP_URL
* @description MongoDB app table access URL
* @global
* @type {String}
*/
MONGO_APP_URL:
'mongodb+srv://USERNAME:PASSWORD@PROJECT-ID.CLOUD-PROVIDER.mongodb.net/DATABASE?retryWrites=true&w=majority',

/**
* @const GCP_STORAGE_BUCKET
* @description GCP storage bucket address
* @global
* @type {String}
*/
GCP_STORAGE_BUCKET: 'development.PROJECT-ID.appspot.com',

/**
* @const TEST_AUTH_KEY
* @description Test JWT token for auth bypass
* @global
* @type {String}
*/
TEST_AUTH_KEY: 'some-sample-jwt-token',
},
env_staging: {
Expand Down
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -523,6 +523,11 @@ MigrationBackup/

# Ionide (cross platform F# VS Code tools) working folder
.ionide/

#JSDoc
out

# Git Secret
.gitsecret/keys/random_seed
!*.secret
.env.js
Expand Down
79 changes: 79 additions & 0 deletions .jsdoc.conf.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/** Documentation Template for Module */
/**
* @deprecated - If module has been deprecated
*
* @module module.path.name - To denote the module with its parents
* @description - To write the description of the module
* @summary - If needed, to summarize the description
*
* @todo - To document pending work
*
* @requires packageName - To denote required package
*
* @see module:path.name - To reference another module
* {@link url|link text} - To link another part of documentation
*
* @version 0.0.0 - To denote module version
* @since - To denote app version when the module was added
*/

/** Documentation Template for Function */
/**
* @deprecated - If module/method has been deprecated
*
* @function methodName - To denote the module with its parents
* @description - To write the description of the module
* @summary - If needed, to summarize the description
* @private - if module is local to file
* @package - if module is exported
* @async - if function is asynchronous
*
* @param {typeName} - Type of paramter required
*
* @return {typeName} - Type of return variable
*
* @this reference - To denote what this references
* @throws {exceptionTypeName} - To denote what is thrown for an error
*
* @todo - To document pending work
*
* @see module:path.name - To reference parent module
* @see {@link path|link text} - To link another part of documentation
*
* @version 0.0.0 - To denote module version
* @since - To denote app version when the module was added
*/

/** Documentation Template for Variable */
/**
* @summary - summary, if needed, for the variable
* @description - desciption, if needed, for the variable
* @const name - if variable is a const
*
* @global - if it is an environment variable
* @type {typeName} - if variable is not an object
* @default value - if default value exists
*
* @see module:path.name - if object of module
*/

/** Description for item/function/module */
module.exports = {
plugins: ['plugins/markdown'],
recursiveDepth: 20,
source: {
exclude: ['node_module', '.gitsecret', '.git', 'test'],
include: ['.env_sample.js'],
includePattern: '.+\\.js$',
excludePattern: '(^|\\/|\\\\)_',
},
sourceType: 'module',
tags: {
allowUnknownTags: true,
dictionaries: ['jsdoc'],
},
templates: {
cleverLinks: false,
monospaceLinks: false,
},
};
98 changes: 80 additions & 18 deletions app.js
Original file line number Diff line number Diff line change
@@ -1,47 +1,92 @@
// Import all libraries
/**
* @module app
* @description The Node.js Application for Monday Morning's Project Infinity, codenamed Project Reclamation
*
* @requires express
* @requires express-session
* @requires connect-mongodb-session
* @requires apollo-server-session
* @requires cookie-parser
* @requires csurf
* @requires cors
* @requires errorhandler - Only in development
* @requires module:app.router
* @requires module:app.mongoose
* @requires module:app.firebase
* @requires module:app.winston
*
* @version 0.1.0
* @since 0.1.0
*/

const express = require('express');
const session = require('express-session');
const MongoDBStore = require('connect-mongodb-session')(session);
const { ApolloServer } = require('apollo-server-express');
const cookieParser = require('cookie-parser');
const csrf = require('csurf');
const errorhandler = require('errorhandler');
const cors = require('cors');
const winston = require('./config/winston');

//TODO: use star instead of slash for docs
//TODO: error handler class

// Import router
/**
* @summary Express Router Object
* @description Import and initialize the express router
* @constant router
*
* @type {express.Router}
*
* @see module:app.router
*/
const router = require('./routes');

// Initialize MongoDB and Firebase Admin SDK
/** Initialize Mongoose and Firebase */
require('./config/mongoose');
require('./config/firebase');

// Initialise Express Server and define server port
/**
* @summary Main Express Application
* @description Initialize Express Server
* @constant app
*
* @type {express.Express}
*/
const app = express();

/**
* @description Server Port
* @constant PORT
*
* @type {Number}
* @default 8080
*/
const PORT = process.env.PORT || 8080;

// Setup Cross-Origin Resource Sharing for the development environment
var corsOptions = {
/**
* @summary Cross Origin Options
* @description Setup Cross-Origin Resource Sharing for the development environment
* @constant corsOptions
*
* @type {String}
* @default http://localhost:3000
*/
const corsOptions = {
origin:
!process.env.NODE_ENV || process.env.NODE_ENV !== 'production'
? 'http://localhost:3000'
: 'https://mondaymorning.nitrkl.ac.in',
};
app.use(cors(corsOptions));

// Use Cookie Parse, JSON and Encoded URL Body Parser, and CSURF in Express
/** Use Cookie Parse, JSON and Encoded URL Body Parser, and CSURF in Express */
app.use(cookieParser());
app.use(csrf({ cookie: true }));

// Use Error Handler in development environment
/** Use Error Handler in development environment */
if (!process.env.NODE_ENV || process.env.NODE_ENV !== 'production') {
app.use(errorhandler());
app.use(require('errorhandler')());
}

// Use Express Session (w/ MongoDB Store in Production)
/** Use Express Session and MongoDB Store for Production */
if (!process.env.NODE_ENV || process.env.NODE_ENV !== 'production') {
app.use(
session({
Expand All @@ -52,6 +97,13 @@ if (!process.env.NODE_ENV || process.env.NODE_ENV !== 'production') {
})
);
} else {
/**
* @summary MongoDB Store
* @description initialize mongodb store with required configuration
* @constant store
*
* @type {MongoDBStore}
*/
const store = new MongoDBStore({
uri: process.env.MONGO_SESSION_URL,
collection: 'sessionCacheStore',
Expand Down Expand Up @@ -80,7 +132,13 @@ if (!process.env.NODE_ENV || process.env.NODE_ENV !== 'production') {
);
}

// Initialise the Apollo Server
/**
* @summary Main Apollo Server
* @description initialize Apollo server with required configration and attach schema
* @constant apolloServer
*
* @type {ApolloServer}
*/
const apolloServer = new ApolloServer({
schema: require('./gql/schema'),
context: ({ req, res }) => ({
Expand All @@ -93,13 +151,13 @@ const apolloServer = new ApolloServer({
debug: !process.env.NODE_ENV || process.env.NODE_ENV !== 'production',
});

// Attach Express Server with Apollo Server
/** Attach Express Server with Apollo Server */
apolloServer.applyMiddleware({ app, path: '/v1/graph', cors: corsOptions });

// Attach Express Router
/** Attach Express Router */
app.use(router);

// Start Express Server on defined port
/** Start Express Server on defined port */
app.listen(PORT, function (err) {
if (err) {
winston.error(new Error(`Reclamation Server | App | Express Server Error on Port ${PORT}`), err);
Expand All @@ -108,4 +166,8 @@ app.listen(PORT, function (err) {
winston.info(`Reclamation Server | App | Express Server Started on Port ${PORT}`);
});

/**
* @description Main Express Application
* @type {express.Express}
*/
module.exports = app;
32 changes: 29 additions & 3 deletions config/firebase.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,20 @@
/**
* @module app.firebase
* @description Firebase Confguration file
*
* @requires firebase-admin
* @requires module:app.winston
*
* @version 0.1.0
* @since 0.1.0
*/

const admin = require('firebase-admin');
const firebaseServiceAccount = require('./firebase-service-account.json');
const winston = require('./winston');

try {
/** Inititalize Firebase Admin SDK with required configuration */
admin.initializeApp({
credential: admin.credential.cert(firebaseServiceAccount),
storageBucket: process.env.GCP_STORAGE_BUCKET,
Expand All @@ -13,6 +25,20 @@ try {
return;
}

const auth = admin.auth();
const bucket = admin.storage().bucket();
module.exports = { auth, bucket };
module.exports = {
/**
* @description Firebase Authentication Library
* @constant
*
* @type {admin.auth.Auth}
*/
auth: admin.auth(),

/**
* @description Firebase Storage Library
* @constant
*
* @type {admin.storage.Storage}
*/
bucket: admin.storage().bucket(),
};
Loading