Skip to content

Commit

Permalink
Formatting improvements to app.js
Browse files Browse the repository at this point in the history
  • Loading branch information
sulkaharo committed Aug 23, 2017
1 parent 918ecc2 commit 530df90
Showing 1 changed file with 43 additions and 55 deletions.
98 changes: 43 additions & 55 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,17 +84,17 @@ function create(env, ctx) {
//app.get('/package.json', software);

// Allow static resources to be cached for week
var maxAge = 7*24*60*60*1000;
var maxAge = 7 * 24 * 60 * 60 * 1000;

if (process.env.NODE_ENV === 'development') {
maxAge = 10;
console.log('Development environment detected, setting static file cache age to 10 seconds');
app.get('/nightscout.appcache', function(req, res){
res.sendStatus(404);
});
}
maxAge = 10;
console.log('Development environment detected, setting static file cache age to 10 seconds');

app.get('/nightscout.appcache', function(req, res) {
res.sendStatus(404);
});
}

//TODO: JC - changed cache to 1 hour from 30d ays to bypass cache hell until we have a real solution
var staticFiles = express.static(env.static_files, {
maxAge: maxAge
Expand All @@ -110,63 +110,51 @@ function create(env, ctx) {
// serve the static content
app.use(tmpFiles);

if (process.env.NODE_ENV !== 'development') {

/*
var bundle = require('./bundle')(env);
app.use(bundle);
*/

if (process.env.NODE_ENV !== 'development') {

console.log('Production environment detected, enabling Minify');

var minify = require('express-minify');
console.log('Production environment detected, enabling Minify');

//app.use(minify());
var minify = require('express-minify');
var myUglifyJS = require('uglify-js');
var myCssmin = require('cssmin');

var myUglifyJS = require('uglify-js');
var myCssmin = require('cssmin');
app.use(minify({
js_match: /\.js/,
css_match: /\.css/,
sass_match: /scss/,
less_match: /less/,
stylus_match: /stylus/,
coffee_match: /coffeescript/,
json_match: /json/,
uglifyJS: myUglifyJS,
cssmin: myCssmin,
cache: __dirname + '/cache',
onerror: undefined,
}));

app.use(minify({
js_match: /\.js/,
css_match: /\.css/,
sass_match: /scss/,
less_match: /less/,
stylus_match: /stylus/,
coffee_match: /coffeescript/,
json_match: /json/,
uglifyJS: myUglifyJS,
cssmin: myCssmin,
cache: __dirname + '/cache',
onerror: undefined,
}));
}

}
// if this is dev environment, package scripts on the fly
// if production, rely on postinstall script to run packaging for us

// if this is dev environment, package scripts on the fly
// if production, rely on postinstall script to run packaging for us
if (process.env.NODE_ENV === 'development') {

if (process.env.NODE_ENV === 'development') {

var webpack = require("webpack");
var webpack_conf = require('./webpack.config');
var webpack = require("webpack");
var webpack_conf = require('./webpack.config');

webpack(webpack_conf, function(err, stats) {
webpack(webpack_conf, function(err, stats) {

var json = stats.toJson() // => webpack --json
var json = stats.toJson() // => webpack --json

var options = {
noColor: true
};
var options = {
noColor: true
};

console.log(prettyjson.render(json.errors, options));
console.log(prettyjson.render(json.assets, options));
console.log(prettyjson.render(json.errors, options));
console.log(prettyjson.render(json.assets, options));

// console.log(err); // => fatal compiler error (rar)
// console.log(json.errors); // => array of errors
// console.log(json.warnings); // => array of warnings
});
}
});
}

// Handle errors with express's errorhandler, to display more readable error messages.
var errorhandler = require('errorhandler');
Expand Down

0 comments on commit 530df90

Please sign in to comment.