Skip to content
This repository has been archived by the owner on Oct 14, 2020. It is now read-only.

Commit

Permalink
back to grunt
Browse files Browse the repository at this point in the history
  • Loading branch information
gpbmike committed Apr 17, 2014
1 parent 8b1f59e commit f98ab5f
Show file tree
Hide file tree
Showing 25 changed files with 600 additions and 272 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Expand Up @@ -2,3 +2,6 @@ bower_components/
node_modules/ node_modules/
dist/ dist/
dev/ dev/
.tmp/
tmp/
.sass-cache/
7 changes: 7 additions & 0 deletions Gruntfile.js
@@ -0,0 +1,7 @@
module.exports = function (grunt) {
// measures the time each task takes
require('time-grunt')(grunt);

// load grunt config
require('load-grunt-config')(grunt);
};
65 changes: 32 additions & 33 deletions api/index.js
Expand Up @@ -4,12 +4,11 @@ var compress = require('compression')();
var bodyParser = require('body-parser'); var bodyParser = require('body-parser');
var UglifyJS = require('uglify-js'); var UglifyJS = require('uglify-js');
var CleanCSS = require('clean-css'); var CleanCSS = require('clean-css');
var hljs = require('highlight.js');
var errorhandler = require('errorhandler'); var errorhandler = require('errorhandler');
var api = express(); var api = express();


api.use(morgan('dev')); api.use(morgan('dev'));
// api.use(compress); api.use(compress);
api.use(bodyParser({ limit: '1mb' })); api.use(bodyParser({ limit: '1mb' }));
api.use(errorhandler()); api.use(errorhandler());


Expand All @@ -33,46 +32,44 @@ api.all('*', function(req, res, next){
next(); next();
}); });



api.post('/javascript/', function (req, res) {
api.post('/', function(req, res){


if (!req.param('code')) { if (!req.param('code')) {
res.send(404, ':('); res.send(404, ':(');
} }


var highlighted = hljs.highlightAuto(req.param('code'), ['javascript', 'css']); try {
var output = { language: highlighted.language }; output = UglifyJS.minify(req.param('code'), {

fromString: true,
switch (output.language) { warnings: true,
case 'javascript': compress: {
try { warnings: true
var minified = UglifyJS.minify(req.param('code'), { }
fromString: true, });
warnings: true, } catch (error) {
compress: { // users don't need to see filestructure of server
warnings: true delete error.stack;
} res.json(500, error);
}); }
output.code = minified.code; res.send(output);
output.map = minified.map;
} catch (error) {
delete error.stack;
res.json(500, error);
}
res.send(output);
break;


case 'css': });
output.code = new CleanCSS().minify(req.param('code'));
res.send(output); api.post('/css/', function (req, res) {
break;


default: if (!req.param('code')) {
res.json(500, 'Sorry, we could not figure out what language you are trying to compress.'); res.send(404, ':(');
} }

var output = {
code: new CleanCSS().minify(req.param('code'))
};

res.send(output);

}); });


api.post('/:fileName', function (req, res) { api.post('/gz/:fileName', function (req, res) {
compress(req, res, function (error) { compress(req, res, function (error) {
if (error) { if (error) {
res.json(error); res.json(error);
Expand All @@ -87,4 +84,6 @@ api.all('*', function (req, res) {
res.send(404); res.send(404);
}); });


api.listen(3001); api.listen(3000, function() {
console.log('Server listening on port 3000');
});

0 comments on commit f98ab5f

Please sign in to comment.