Skip to content
This repository has been archived by the owner on Aug 30, 2021. It is now read-only.

feat(core): disable Angular debug data in production #1457

Merged
merged 1 commit into from
Aug 28, 2016
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
1 change: 1 addition & 0 deletions config/lib/express.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ module.exports.initLocalVariables = function (app) {
app.locals.livereload = config.livereload;
app.locals.logo = config.logo;
app.locals.favicon = config.favicon;
app.locals.env = process.env.NODE_ENV;

// Passing the request url to environment locals
app.use(function (req, res, next) {
Expand Down
1 change: 1 addition & 0 deletions modules/core/client/app/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
var applicationModuleName = 'mean';

var service = {
applicationEnvironment: window.env,
applicationModuleName: applicationModuleName,
applicationModuleVendorDependencies: ['ngResource', 'ngAnimate', 'ngMessages', 'ui.router', 'ui.bootstrap', 'ngFileUpload', 'ngImgCrop'],
registerModule: registerModule
Expand Down
8 changes: 6 additions & 2 deletions modules/core/client/app/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,17 @@
.module(app.applicationModuleName)
.config(bootstrapConfig);

function bootstrapConfig($locationProvider, $httpProvider) {
function bootstrapConfig($compileProvider, $locationProvider, $httpProvider) {
$locationProvider.html5Mode(true).hashPrefix('!');

$httpProvider.interceptors.push('authInterceptor');

// Disable debug data for production environment
// @link https://docs.angularjs.org/guide/production
$compileProvider.debugInfoEnabled(app.applicationEnvironment !== 'production');
}

bootstrapConfig.$inject = ['$locationProvider', '$httpProvider'];
bootstrapConfig.$inject = ['$compileProvider', '$locationProvider', '$httpProvider'];

// Then define the init function for starting up the application
angular.element(document).ready(init);
Expand Down
3 changes: 2 additions & 1 deletion modules/core/server/views/layout.server.view.html
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@

<!--Embedding The User Object-->
<script type="text/javascript">
var user = {{ user | json | safe }};
var user = {{ user | json | safe }},
env = "{{ env }}";
</script>

<!--Load The Socket.io File-->
Expand Down
39 changes: 37 additions & 2 deletions modules/core/tests/server/core.server.config.tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,18 @@ var _ = require('lodash'),
path = require('path'),
fs = require('fs'),
mock = require('mock-fs'),
request = require('supertest'),
config = require(path.resolve('./config/config')),
logger = require(path.resolve('./config/lib/logger')),
seed = require(path.resolve('./config/lib/seed'));
seed = require(path.resolve('./config/lib/seed')),
express = require(path.resolve('./config/lib/express'));

/**
* Globals
*/
var user1,
var app,
agent,
user1,
admin1,
userFromSeedConfig,
adminFromSeedConfig,
Expand Down Expand Up @@ -507,4 +511,35 @@ describe('Configuration Tests:', function () {
fileTransport.should.be.false();
});
});

describe('Testing exposing environment as a variable to layout', function () {

['development', 'production', 'test'].forEach(function(env) {
it('should expose environment set to ' + env, function (done) {
// Set env to development for this test
process.env.NODE_ENV = env;

// Gget application
app = express.init(mongoose);
agent = request.agent(app);

// Get rendered layout
agent.get('/')
.expect('Content-Type', 'text/html; charset=utf-8')
.expect(200)
.end(function (err, res) {
// Set env back to test
process.env.NODE_ENV = 'test';
// Handle errors
if (err) {
return done(err);
}
res.text.should.containEql('env = "' + env + '"');
return done();
});
});
});

});

});