Advertisement
ktyc

Don't know

Jun 29th, 2017
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.33 KB | None | 0 0
  1. [https://github.com/meanjs/mean](http://)
  2. I used the command below from the link above
  3. ```
  4. git clone https://github.com/meanjs/mean.git meanjs
  5. ```
  6. I found the file you mentioned in /home/ktyc/meanjs/config/config.js and I pasted it below
  7. ```
  8. 'use strict';
  9.  
  10. /**
  11. * Module dependencies.
  12. */
  13. var _ = require('lodash'),
  14. chalk = require('chalk'),
  15. glob = require('glob'),
  16. fs = require('fs'),
  17. path = require('path');
  18.  
  19. /**
  20. * Get files by glob patterns
  21. */
  22. var getGlobbedPaths = function (globPatterns, excludes) {
  23. // URL paths regex
  24. var urlRegex = new RegExp('^(?:[a-z]+:)?\/\/', 'i');
  25.  
  26. // The output array
  27. var output = [];
  28.  
  29. // If glob pattern is array then we use each pattern in a recursive way, otherwise we use glob
  30. if (_.isArray(globPatterns)) {
  31. globPatterns.forEach(function (globPattern) {
  32. output = _.union(output, getGlobbedPaths(globPattern, excludes));
  33. });
  34. } else if (_.isString(globPatterns)) {
  35. if (urlRegex.test(globPatterns)) {
  36. output.push(globPatterns);
  37. } else {
  38. var files = glob.sync(globPatterns);
  39. if (excludes) {
  40. files = files.map(function (file) {
  41. if (_.isArray(excludes)) {
  42. for (var i in excludes) {
  43. if (excludes.hasOwnProperty(i)) {
  44. file = file.replace(excludes[i], '');
  45. }
  46. }
  47. } else {
  48. file = file.replace(excludes, '');
  49. }
  50. return file;
  51. });
  52. }
  53. output = _.union(output, files);
  54. }
  55. }
  56.  
  57. return output;
  58. };
  59.  
  60. /**
  61. * Validate NODE_ENV existence
  62. */
  63. var validateEnvironmentVariable = function () {
  64. var environmentFiles = glob.sync('./config/env/' + process.env.NODE_ENV + '.js');
  65. console.log();
  66. if (!environmentFiles.length) {
  67. if (process.env.NODE_ENV) {
  68. console.error(chalk.red('+ Error: No configuration file found for "' + process.env.NODE_ENV + '" environment using development instead'));
  69. } else {
  70. console.error(chalk.red('+ Error: NODE_ENV is not defined! Using default development environment'));
  71. }
  72. process.env.NODE_ENV = 'development';
  73. }
  74. // Reset console color
  75. console.log(chalk.white(''));
  76. };
  77.  
  78. /** Validate config.domain is set
  79. */
  80. var validateDomainIsSet = function (config) {
  81. if (!config.domain) {
  82. console.log(chalk.red('+ Important warning: config.domain is empty. It should be set to the fully qualified domain of the app.'));
  83. }
  84. };
  85.  
  86. /**
  87. * Validate Secure=true parameter can actually be turned on
  88. * because it requires certs and key files to be available
  89. */
  90. var validateSecureMode = function (config) {
  91.  
  92. if (!config.secure || config.secure.ssl !== true) {
  93. return true;
  94. }
  95.  
  96. var privateKey = fs.existsSync(path.resolve(config.secure.privateKey));
  97. var certificate = fs.existsSync(path.resolve(config.secure.certificate));
  98.  
  99. if (!privateKey || !certificate) {
  100. console.log(chalk.red('+ Error: Certificate file or key file is missing, falling back to non-SSL mode'));
  101. console.log(chalk.red(' To create them, simply run the following from your shell: sh ./scripts/generate-ssl-certs.sh'));
  102. console.log();
  103. config.secure.ssl = false;
  104. }
  105. };
  106.  
  107. /**
  108. * Validate Session Secret parameter is not set to default in production
  109. */
  110. var validateSessionSecret = function (config, testing) {
  111.  
  112. if (process.env.NODE_ENV !== 'production') {
  113. return true;
  114. }
  115.  
  116. if (config.sessionSecret === 'MEAN') {
  117. if (!testing) {
  118. console.log(chalk.red('+ WARNING: It is strongly recommended that you change sessionSecret config while running in production!'));
  119. console.log(chalk.red(' Please add `sessionSecret: process.env.SESSION_SECRET || \'super amazing secret\'` to '));
  120. console.log(chalk.red(' `config/env/production.js` or `config/env/local.js`'));
  121. console.log();
  122. }
  123. return false;
  124. } else {
  125. return true;
  126. }
  127. };
  128.  
  129. /**
  130. * Initialize global configuration files
  131. */
  132. var initGlobalConfigFolders = function (config, assets) {
  133. // Appending files
  134. config.folders = {
  135. server: {},
  136. client: {}
  137. };
  138.  
  139. // Setting globbed client paths
  140. config.folders.client = getGlobbedPaths(path.join(process.cwd(), 'modules/*/client/'), process.cwd().replace(new RegExp(/\\/g), '/'));
  141. };
  142.  
  143. /**
  144. * Initialize global configuration files
  145. */
  146. var initGlobalConfigFiles = function (config, assets) {
  147. // Appending files
  148. config.files = {
  149. server: {},
  150. client: {}
  151. };
  152.  
  153. // Setting Globbed model files
  154. config.files.server.models = getGlobbedPaths(assets.server.models);
  155.  
  156. // Setting Globbed route files
  157. config.files.server.routes = getGlobbedPaths(assets.server.routes);
  158.  
  159. // Setting Globbed config files
  160. config.files.server.configs = getGlobbedPaths(assets.server.config);
  161.  
  162. // Setting Globbed socket files
  163. config.files.server.sockets = getGlobbedPaths(assets.server.sockets);
  164.  
  165. // Setting Globbed policies files
  166. config.files.server.policies = getGlobbedPaths(assets.server.policies);
  167.  
  168. // Setting Globbed js files
  169. config.files.client.js = getGlobbedPaths(assets.client.lib.js, 'public/').concat(getGlobbedPaths(assets.client.js, ['public/']));
  170.  
  171. // Setting Globbed css files
  172. config.files.client.css = getGlobbedPaths(assets.client.lib.css, 'public/').concat(getGlobbedPaths(assets.client.css, ['public/']));
  173.  
  174. // Setting Globbed test files
  175. config.files.client.tests = getGlobbedPaths(assets.client.tests);
  176. };
  177.  
  178. /**
  179. * Initialize global configuration
  180. */
  181. var initGlobalConfig = function () {
  182. // Validate NODE_ENV existence
  183. validateEnvironmentVariable();
  184.  
  185. // Get the default assets
  186. var defaultAssets = require(path.join(process.cwd(), 'config/assets/default'));
  187.  
  188. // Get the current assets
  189. var environmentAssets = require(path.join(process.cwd(), 'config/assets/', process.env.NODE_ENV)) || {};
  190.  
  191. // Merge assets
  192. var assets = _.merge(defaultAssets, environmentAssets);
  193.  
  194. // Get the default config
  195. var defaultConfig = require(path.join(process.cwd(), 'config/env/default'));
  196.  
  197. // Get the current config
  198. var environmentConfig = require(path.join(process.cwd(), 'config/env/', process.env.NODE_ENV)) || {};
  199.  
  200. // Merge config files
  201. var config = _.merge(defaultConfig, environmentConfig);
  202.  
  203. // read package.json for MEAN.JS project information
  204. var pkg = require(path.resolve('./package.json'));
  205. config.meanjs = pkg;
  206.  
  207. // Extend the config object with the local-NODE_ENV.js custom/local environment. This will override any settings present in the local configuration.
  208. config = _.merge(config, (fs.existsSync(path.join(process.cwd(), 'config/env/local-' + process.env.NODE_ENV + '.js')) && require(path.join(process.cwd(), 'config/env/local-' + process.env.NODE_ENV + '.js'))) || {});
  209.  
  210. // Initialize global globbed files
  211. initGlobalConfigFiles(config, assets);
  212.  
  213. // Initialize global globbed folders
  214. initGlobalConfigFolders(config, assets);
  215.  
  216. // Validate Secure SSL mode can be used
  217. validateSecureMode(config);
  218.  
  219. // Validate session secret
  220. validateSessionSecret(config);
  221.  
  222. // Print a warning if config.domain is not set
  223. validateDomainIsSet(config);
  224.  
  225. // Expose configuration utilities
  226. config.utils = {
  227. getGlobbedPaths: getGlobbedPaths,
  228. validateSessionSecret: validateSessionSecret
  229. };
  230.  
  231. return config;
  232. };
  233.  
  234. /**
  235. * Set configuration object
  236. */
  237. module.exports = initGlobalConfig();
  238.  
  239. ```
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement