Permalink
Browse files

Switching GitCDN to Heroku

Signed-off-by: Shane Gadsby <Shane.Gadsby@usq.edu.au>
  • Loading branch information...
schme16 committed Jan 27, 2016
1 parent 7e2412a commit 678c3154338552e554708c0b3c87f50b0f338601
Showing with 13 additions and 43 deletions.
  1. +1 −0 Procfile
  2. +9 −18 server.js → index.js
  3. +3 −25 package.json
View
@@ -0,0 +1 @@
web: node --expose-gc index.js
View
@@ -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
@@ -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)
}));
}
@@ -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;
@@ -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))
@@ -152,8 +148,6 @@ catch(e) {}
pmx.action('cache:empty', actions.emptyCache);
/*Serve the site icon*/
app.use('/favicon.ico', faviconFunc)
@@ -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);
View
@@ -1,6 +1,6 @@
{
"name": "GitCDN",
"version": "1.0.0",
"version": "1.0.1",
"description": "GitCDN server",
"keywords": [
"OpenShift",
@@ -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.