Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

bit of optimisation - ie do not keep parsing the done files. Need to …

…automatically remove these over time or only re-parse after 1 hour of last check
  • Loading branch information...
commit 463f9f3610be2dfd57e9af4aa2eaed401a30ab46 1 parent 2aa4066
Remy Sharp authored

Showing 2 changed files with 27 additions and 14 deletions. Show diff stats Hide diff stats

  1. +25 12 app.js
  2. +2 2 prefix.js
37 app.js
@@ -22,6 +22,9 @@ path.exists(__dirname + '/public/jobs', function (exists) {
22 22 }
23 23 });
24 24
  25 +function urlAsPath(url) {
  26 + return url.toLowerCase().replace(/.*?:\/\//, '').replace(/\//g, '_');
  27 +}
25 28
26 29 var app = module.exports = express.createServer();
27 30
@@ -71,20 +74,30 @@ app.get('/check.json', function (req, res) {
71 74 prefix.send({ type: 'start', url: req.query.url, dirtyExit: true });
72 75 });
73 76
74   -app.get(/\/(.*)?/, function (req, res) {
75   - console.log(req.headers);
76   - var prefix = cp.fork(__dirname + '/prefix.js');
77   -
78   - prefix.on('message', function(event) {
79   - console.log(event);
80   - if (event.type == 'end') {
81   - res.send('<a href="/jobs/' + event.job + '.zip">' + event.job + '.zip</a>');
  77 +app.get(/\/check\/(.*)?/, function (req, res) {
  78 + var job = urlAsPath(req.params[0]);
  79 + path.exists(__dirname + '/public/jobs/' + job + '.zip', function (exists) {
  80 + var ready = function () {
  81 + res.send('<a href="/jobs/' + job + '.zip">' + job + '.zip</a>');
  82 + };
  83 +
  84 + if (!exists) {
  85 + var prefix = cp.fork(__dirname + '/prefix.js');
  86 +
  87 + prefix.on('message', function(event) {
  88 + // console.log(event);
  89 + if (event.type == 'end') {
  90 + ready();
  91 + }
  92 + // res.writeHead(200, { 'content-type': 'text/css' });
  93 + // res.end('');
  94 + });
  95 +
  96 + prefix.send({ type: 'start', url: req.params[0] });
  97 + } else {
  98 + ready();
82 99 }
83   - // res.writeHead(200, { 'content-type': 'text/css' });
84   - // res.end('');
85 100 });
86   -
87   - prefix.send({ type: 'start', url: req.params[0] });
88 101 });
89 102
90 103 app.listen(process.env.PORT || 8000);
4 prefix.js
@@ -44,7 +44,7 @@ Prefix.prototype.dirty = false;
44 44 Prefix.prototype.end = function () {
45 45 var self = this;
46 46
47   - var child = exec('zip ' + __dirname + '/public/jobs/' + self.job + '.zip *.css', { cwd: self.dir }, function (error, stdout, stderr) {
  47 + var child = exec('zip ' + __dirname + '/public/jobs/' + self.job + '.zip *.*', { cwd: self.dir }, function (error, stdout, stderr) {
48 48 if (error !== null) {
49 49 console.log('exec error: ' + error);
50 50 }
@@ -317,7 +317,7 @@ function retrofit(css, lint) {
317 317 }
318 318
319 319 function urlAsPath(url) {
320   - return url.toLowerCase().replace(/.*?:\/\//, '').replace(/\//g, '_');
  320 + return url.toLowerCase().replace(/.*?:\/\//, '').replace(/\?/, '-').replace(/\//g, '_');
321 321 }
322 322
323 323

0 comments on commit 463f9f3

Please sign in to comment.
Something went wrong with that request. Please try again.