Skip to content
This repository has been archived by the owner on Jun 23, 2023. It is now read-only.

Commit

Permalink
Switching GitCDN to Heroku
Browse files Browse the repository at this point in the history
Signed-off-by: Shane Gadsby <Shane.Gadsby@usq.edu.au>
  • Loading branch information
schme16 committed Jan 27, 2016
1 parent 7e2412a commit 678c315
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 43 deletions.
1 change: 1 addition & 0 deletions Procfile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
web: node --expose-gc index.js
27 changes: 9 additions & 18 deletions server.js → index.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
#!/bin/env node

//Send http data to keymetrics.io
var pmx = require('pmx');
pmx.init();

favicon = require('zlib').gzipSync(require('fs').readFileSync('website/favicon.ico'))


//Serves the favicon
function faviconFunc (req, res) {
res.setHeader('Content-Encoding', 'gzip');
res.setHeader('Content-Type', 'image/x-icon');
res.send(favicon);
res.setHeader('Content-Encoding', 'gzip');
res.setHeader('Content-Type', 'image/x-icon');
res.send(favicon);
}

//Serves the cdn route
Expand All @@ -24,9 +21,8 @@ function cdnFunc(req, res) {
}).on('error', function(err) {
res.statusCode = 500;
res.end();

var err = new Error('Status 500: couldn\'t pipe file to client || ' + meta.user + '/' + meta.repo + '/' + body.sha + '/' + meta.filePath);
pmx.notify(err);
console.log(err)
}));
}

Expand Down Expand Up @@ -68,20 +64,20 @@ function repoFunc (req, res) {
}
catch (e) {
var err = new Error(e);
pmx.notify(err);
console.log(err)
}
if (meta.gist) meta.repo += '/raw';
if (body && (body.sha || (body.history && body.history[0] && body.history[0].version))) lastCall(meta, body.sha || body.history[0].version, req, res, refreshCache);
else{
if (!refreshCache) res.sendStatus(500)
var err = new Error('SHA1 hash is missing in /repo -> request: ' + req.path + '; JSON=' + JSON.stringify(body));
pmx.notify(err);
console.log(err)
}
}
else {
if (!refreshCache) res.sendStatus(500)
var err = new Error('Status 500: ' + meta.user + '/' + meta.repo + '/' + body.sha + '/' + meta.filePath);
pmx.notify(err);
console.log(err)
}
meta = null;
options = null;
Expand All @@ -105,7 +101,7 @@ function lastCall (meta, sha, req, res, cacheing) {
else {
if (!cacheing) res.sendStatus(500);
var err = new Error('Status 500: SHA1 hash is missing in lastCall() || ' + meta.user + '/' + meta.repo + '/' + sha + '/' + meta.filePath);
pmx.notify(err);
console.log(err)
}

fs.writeFile('store-cache', JSON.stringify(cache))
Expand Down Expand Up @@ -152,8 +148,6 @@ catch(e) {}



pmx.action('cache:empty', actions.emptyCache);


/*Serve the site icon*/
app.use('/favicon.ico', faviconFunc)
Expand All @@ -171,10 +165,7 @@ app.get('/repo/*', repoFunc)


//console.log(global)
setInterval(global.gc, 5000)

setInterval(global.gc, 15000)

//Send error data to keymetrics.io
app.use(pmx.expressErrorHandler());

app.listen(8080);
28 changes: 3 additions & 25 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "GitCDN",
"version": "1.0.0",
"version": "1.0.1",
"description": "GitCDN server",
"keywords": [
"OpenShift",
Expand All @@ -19,39 +19,17 @@
"url": "git@github.com:schme16/gitcdn.xyz.git"
},
"engines": {
"node": ">= 0.12.6",
"npm": ">= 1.0.0"
"node": ">= 5.5.5"
},
"dependencies": {
"cors": "^2.6.0",
"express": "^4.12.3",
"hapi": "^8.8.0",
"mime": "^1.3.4",
"pm2": "latest",
"pmx": "latest",
"request": "^2.55.0"
},
"devDependencies": {},
"bundleDependencies": [],
"private": true,
"main": "server.js",
"apps": [
{
"name": "GitCDN",
"script": "server.js",
"error_file": "err.log",
"out_file": "out.log",
"merge_logs": true,
"log_date_format": "YYYY-MM-DD HH:mm Z",
"max_memory_restart": "100M",
"watch": [
"server.js",
"package.json"
],
"node-args": "--always-compact --max_old_space_size=20 --nouse-idle-notification --expose-gc",
"ignore_watch": [
"store-cache"
]
}
"main": "index.js",
]
}

0 comments on commit 678c315

Please sign in to comment.