forked from mozilla/galaxy
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
deploy on stackato (fixes mozilla#96)
- Loading branch information
Showing
9 changed files
with
255 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,135 @@ | ||
var fs = require('fs'); | ||
var http = require('http'); | ||
var zlib = require('zlib'); | ||
|
||
var nodeStatic = require('node-static'); | ||
|
||
|
||
const SERVER_HTML = '/server.html'; | ||
const REWRITES = [ | ||
{from: '^/([\?].*)?$', to: SERVER_HTML}, | ||
{from: '^/(friends|submit|game|genre|user|settings|leaderboard|developer|review|tests|debug)([\?].*)?$', to: SERVER_HTML}, | ||
]; | ||
const STRIP_TRAILING_SLASHES = true; | ||
const TEMPLATE_404 = SERVER_HTML; | ||
|
||
|
||
function patchVaryHeader(headers, header) { | ||
var v = headers['Vary']; | ||
return headers['Vary'] = (v && v !== header ? v + ', ' : '') + header; | ||
} | ||
|
||
/* Check if we should consider sending a deflate version of the file based on the | ||
* file content type and client's Accept-Encoding header value. | ||
*/ | ||
nodeStatic.Server.prototype.deflateOk = function(req, contentType) { | ||
var enable = this.options.deflate; | ||
if (enable && | ||
(typeof enable === 'boolean' || | ||
(contentType && enable instanceof RegExp && | ||
enable.test(contentType)))) { | ||
var acceptEncoding = req.headers['accept-encoding']; | ||
return acceptEncoding && acceptEncoding.indexOf('deflate') >= 0; | ||
} | ||
return false; | ||
}; | ||
|
||
/* Monkeypatching `node-static`'s gzip so we can do it on the fly and also | ||
* support deflate (which results in smaller responses). | ||
*/ | ||
nodeStatic.Server.prototype.respondGzip = function(pathname, status, | ||
contentType, _headers, | ||
files, stat, req, res, | ||
finish) { | ||
var that = this; | ||
var gzipOk = that.gzipOk(req, contentType); | ||
var deflateOk = that.deflateOk(req, contentType); | ||
if (!(files.length === 1 && (gzipOk || deflateOk))) { | ||
// Client doesn't want deflate/gzip or we're sending multiple files. | ||
return that.respondNoGzip(pathname, status, contentType, _headers, files, | ||
stat, req, res, finish); | ||
} | ||
|
||
var compFile; | ||
var compLib; | ||
|
||
if (deflateOk) { | ||
compFile = files[0] + '.deflate'; | ||
compLib = zlib.createDeflate(); | ||
_headers['Content-Encoding'] = 'deflate'; | ||
} else { | ||
compFile = files[0] + '.gz'; | ||
compLib = zlib.createGzip(); | ||
_headers['Content-Encoding'] = 'gzip'; | ||
} | ||
|
||
var inStr = fs.createReadStream(files[0]); | ||
var outStr = fs.createWriteStream(compFile); | ||
|
||
patchVaryHeader(_headers, 'Accept-Encoding'); | ||
|
||
inStr.pipe(compLib).pipe(outStr); | ||
|
||
outStr.on('close', function() { | ||
fs.stat(compFile, function(e, stat) { | ||
that.respondNoGzip(pathname, status, contentType, _headers, [compFile], | ||
stat, req, res, finish); | ||
}); | ||
}); | ||
}; | ||
|
||
var fileServer = new nodeStatic.Server('./src', { | ||
// TODO: Set a reasonable `max-age` (issue #41). | ||
cache: 0, | ||
deflate: true, | ||
gzip: true | ||
}); | ||
|
||
|
||
function getRewrite(req, stripslashes) { | ||
var data = {headers: {}}; | ||
REWRITES.forEach(function(rewrite) { | ||
var re = new RegExp(rewrite.from); | ||
if (re.test(req.url)) { | ||
if (rewrite.redirect) { | ||
data.headers['Location'] = data.path; | ||
data.statusCode = rewrite.redirect === 'permanent' ? 301 : 302; | ||
} else { | ||
data.statusCode = 200; | ||
} | ||
data.path = rewrite.to; | ||
} else if (stripslashes && req.url.substr(-1) === '/') { | ||
var slashlessUrl = req.url.substr(0, req.url.length - 1); | ||
if (re.test(slashlessUrl)) { | ||
data.headers['Location'] = slashlessUrl; | ||
data.statusCode = 302; | ||
} | ||
} | ||
}); | ||
return data; | ||
} | ||
|
||
http.createServer(function (req, res) { | ||
req.addListener('end', function () { | ||
if (req.url === '/') { | ||
req.url = SERVER_HTML; | ||
} | ||
fileServer.serve(req, res, function(err, fileRes) { | ||
var rewrite = getRewrite(req, STRIP_TRAILING_SLASHES); | ||
if (rewrite.path) { | ||
fileServer.serveFile(rewrite.path, rewrite.statusCode, | ||
rewrite.headers, req, res); | ||
} else if (rewrite.statusCode) { | ||
res.writeHead(rewrite.statusCode, rewrite.headers); | ||
res.end(); | ||
} else if (err && err.status === 404) { | ||
if (TEMPLATE_404) { | ||
fileServer.serveFile(TEMPLATE_404, 404, {}, req, res); | ||
} else { | ||
res.writeHead(404, {'Content-Type': 'text/plain'}); | ||
res.end('404'); | ||
} | ||
} | ||
}); | ||
}).resume(); | ||
}).listen(process.env.PORT || 9000); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#!/usr/bin/env bash | ||
|
||
COMMONPLACE=./node_modules/commonplace/bin/commonplace | ||
|
||
find . -name 'src/*.deflate' -delete | ||
find . -name 'src/*.gz' -delete | ||
|
||
npm install | ||
npm install --force [email protected] | ||
|
||
$COMMONPLACE includes | ||
$COMMONPLACE langpacks |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
{ | ||
"name": "galaxy", | ||
"version": "0.0.1", | ||
"engines": { | ||
"node": ">=0.10.x", | ||
"npm": ">=1.1.x" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git://github.com/cvan/galaxy.git" | ||
}, | ||
"dependencies": { | ||
"node-static": "latest" | ||
}, | ||
"scripts": { | ||
"start": "node app.js" | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,6 @@ | ||
define('settings_local', [], function() { | ||
// Use this module for settings to be used in production. | ||
var origin = window.location.origin || ( | ||
window.location.protocol + '//' + window.location.host); | ||
return { | ||
api_url: origin | ||
api_url: 'https://galaxy-api.paas.allizom.org' | ||
}; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta charset="utf-8"> | ||
<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1, maximum-scale=1"> | ||
<title>Mozilla Galaxy</title> | ||
<link rel="stylesheet" href="//fonts.googleapis.com/css?family=Electrolize"> | ||
<link rel="stylesheet" href="//fonts.googleapis.com/css?family=Source+Sans+Pro:200,300,400,600,700,900,200italic,300italic,400italic,600italic,700italic,900italic" type="text/css"> | ||
<link rel="stylesheet" href="/media/css/include.css"> | ||
</head> | ||
<body class="home" data-media="/media/"> | ||
<noscript><p>Sorry, you need JavaScript to use this site.</p></noscript> | ||
<div id="splash-overlay"><div class="throbber"></div></div> | ||
|
||
<header id="site-header" class="header site-header"></header> | ||
|
||
<div class="cloak"></div> | ||
<main> | ||
<div id="page" class="page" role="main"></div> | ||
</main> | ||
|
||
<footer id="site-footer" class="site-footer"></footer> | ||
|
||
<!-- screenshot lightbox --> | ||
<div id="lightbox"> | ||
<section> | ||
<ul class="content"></ul> | ||
<a class="close" href="#">×</a> | ||
</section> | ||
</div> | ||
|
||
<script src="https://login.persona.org/include.js"></script> | ||
<!-- TODO: Make Aviary load as `async` --> | ||
<script src="https://dme0ih8comzn4.cloudfront.net/js/feather.js"></script> | ||
<script src="/media/js/l10n.js"></script> | ||
<script src="//platform.twitter.com/widgets.js" async></script> | ||
<script src="/media/js/include.js"></script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
name: galaxy | ||
|
||
instances: 1 | ||
|
||
framework: | ||
type: node | ||
runtime: node010 | ||
|
||
mem: 64 | ||
|
||
hooks: | ||
pre-push: | ||
- ./deploy.sh | ||
|
||
processes: | ||
web: npm start | ||
|
||
ignores: [".git", "node_modules/*"] |