daily pastebin goal
41%
SHARE
TWEET

index.js revised

a guest Dec 29th, 2016 71 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. 'use strict';
  2.  
  3. var express     = require('express');
  4. var Sequelize   = require('sequelize');
  5.  
  6. /** Handle shits **/
  7. process.on('unhandledRejection', function(reason, promise) {
  8.     console.log("REJECTION : ");
  9.     console.log(reason.message);
  10. });
  11.  
  12. var args        = {};
  13.  
  14. var dbname =  process.env.DB_NAME ? process.env.DB_NAME : 'bri_v1';
  15. var dbuser =  process.env.DB_USER ? process.env.DB_USER : 'root';
  16. var dbpass =  process.env.DB_PASSWORD ? process.env.DB_PASSWORD : 'reza24';
  17. var dbhost =  process.env.DB_HOST ? process.env.DB_HOST : 'localhost';
  18.  
  19. /** Load the modules **/
  20. args.MODULES    = {
  21.     SEQUELIZE   : new Sequelize(dbname, dbuser, dbpass, {
  22.         host    : dbhost,
  23.         dialect : 'mysql',
  24.         pool    : {
  25.             max : 30,
  26.             min : 0,
  27.             idle : 10000
  28.         }
  29.     }),
  30.     DATATYPES   : Sequelize.DataTypes,
  31.     FS          : require('fs'),
  32.     EXPRESS_APP : express(),
  33.     PATH        : require('path'),
  34.     ASYNC       : require('async'),
  35.     CHALK       : require('chalk'),
  36.     UUID        : require('uuid'),
  37.     _           : require('underscore'),
  38.     JWT         : require('jsonwebtoken'),
  39.     NODERSA     : require('node-rsa')
  40. };
  41.  
  42. /** Console Utils **/
  43. args.CONSOLE    = {
  44.     ERROR : args.MODULES.CHALK.white.bgRed.bold,
  45.     INFO : args.MODULES.CHALK.white.bgBlue.bold
  46. };
  47.  
  48. /** Error Defaults **/
  49. args.ERROR      = {
  50.     INTERNAL : {
  51.         code : 500,
  52.         message : "Internal server failure :("
  53.     }
  54. };
  55.  
  56. /** Configs **/
  57. args.CONFIG = {};
  58.  
  59. /** Set file paths **/
  60. args.CONFIG.FILE_PATH = {
  61.     controllerPath  : 'application/controllers/',
  62.     modelPath       : 'application/models/',
  63.     workerPath      : 'application/workers/',
  64.     middlewarePath  : 'application/middlewares/',
  65.     apis            : "apis/"
  66. };
  67.  
  68. /** Setup Middlewares **/
  69. args.MODULES.EXPRESS_APP.use(require('morgan')('combined'));
  70. args.MODULES.EXPRESS_APP.use(require('body-parser').json());
  71. args.MODULES.EXPRESS_APP.use(require('./application/middlewares/UserAuth'));
  72.  
  73. //** Load Models **/
  74. args.models = require('./system/model')(args);
  75.  
  76. /** Load middlewares **/
  77. // karena middleware di pake sama worker, di load dulu atuh middleware nya, baru load worker nya. jangan load worker dulu baru middleware.
  78. args.middlewares = require('./system/middleware')(args);
  79.  
  80. //** Load Workers **/
  81. args.workers = require('./system/worker')(args);
  82.  
  83. /** Load controllers **/
  84. args.controllers = require('./system/controller')(args);
  85.  
  86. /** Setup routers **/
  87. require('./system/router')(args);
  88.  
  89. /** Run 😀 **/
  90. args.MODULES.EXPRESS_APP.listen(3000, function() {
  91.     console.log("Running..");
  92. });
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top