Added gzip support #82

This commit is contained in:
logsol 2014-12-20 05:30:22 +01:00
parent 6f288f00b5
commit f29883d47f
6 changed files with 20 additions and 9 deletions

View file

@ -1,10 +1,11 @@
define([ define([
'http', 'http',
'node-static', 'node-static',
'Server/Api' 'Server/Api',
'zlib'
], ],
function (http, nodeStatic, Api) { function (http, nodeStatic, Api, zlib) {
function HttpServer (options, coordinator) { function HttpServer (options, coordinator) {
options.port = options.port || 1234; options.port = options.port || 1234;
@ -20,7 +21,8 @@ function (http, nodeStatic, Api) {
HttpServer.prototype.init = function (options) { HttpServer.prototype.init = function (options) {
var self = this; var self = this;
var fileServer = new nodeStatic.Server(options.rootDirectory, { cache: options.caching }); //gzip true serves gzip file if there is one with .gz next to the original && if browser supports it
var fileServer = new nodeStatic.Server(options.rootDirectory, { cache: options.caching, gzip: true });
this.server = http.createServer( this.server = http.createServer(
function (req, res) { function (req, res) {
@ -48,7 +50,7 @@ function (http, nodeStatic, Api) {
break; break;
case req.url == '/client.min.js': case req.url == '/client.min.js':
fileServer.serveFile('./client.min.js', 200, {}, req, res); fileServer.serveFile('./build/client.min.js', 200, {}, req, res);
break; break;
case req.url == '/require.js': case req.url == '/require.js':

View file

@ -1,5 +1,5 @@
({ ({
baseUrl: "app", baseUrl: "../app",
paths: { paths: {
"screenfull": "../node_modules/screenfull/dist/screenfull", "screenfull": "../node_modules/screenfull/dist/screenfull",
"socketio": "../node_modules/socket.io/node_modules/socket.io-client/dist/socket.io" "socketio": "../node_modules/socket.io/node_modules/socket.io-client/dist/socket.io"

9
build/build.sh Executable file
View file

@ -0,0 +1,9 @@
#!/bin/bash
if [ -d "build" ]; then
cd build
echo "\\033[1;36mcompiling client scripts...\\033[0m"
rm -f "client.min.js.gz"
../node_modules/requirejs/bin/r.js -o build.js > /dev/null \
&& gzip --keep client.min.js && echo "\\033[1;32mdone.\\033[0m"
cd ..
fi

File diff suppressed because one or more lines are too long

BIN
build/client.min.js.gz Normal file

Binary file not shown.

View file

@ -27,6 +27,6 @@
"config": { "port": "1234" }, "config": { "port": "1234" },
"private": true, "private": true,
"scripts": { "scripts": {
"prestart": "node_modules/requirejs/bin/r.js -o build.js optimize=none > /dev/null && echo '\\033[1;32mcompiled.\\033[0m'" "prestart": "./build/build.sh"
} }
} }