"use strict";
var connect = require('connect');
var http = require('http');
var optimist = require('optimist');
var path = require('path');
var reactMiddleware = require('react-page-middleware');

var equation = require('./modules/equation/module.js')

var express = require('express')

var argv = optimist.argv;

var PROJECT_ROOT = __dirname;
var FILE_SERVE_ROOT = path.join(PROJECT_ROOT, 'pages');

var port = argv.port;

var isServer = !argv.computeForPath;

var serverDefaults = {
  serverRender: true,
  skipES5Shim: false,
  useBrowserBuiltins: false,
  logTiming: true,
  useSourceMaps: true,
  pageRouteRoot: FILE_SERVE_ROOT,
  sourceMapsType: 'linked'
};

var computeDefaults = {
  serverRender: false,
  skipES5Shim: false,
  useBrowserBuiltins: false,
  logTiming: false,
  useSourceMaps: false,
  pageRouteRoot: FILE_SERVE_ROOT,
  sourceMapsType: 'linked'
};

var defaults = isServer ? serverDefaults : computeDefaults;

var buildOptions = {
  projectRoot: PROJECT_ROOT,
  skipES5Shim: argv.skipES5Shim == 'true',      // Skip shim if you know you have
                                                // a very modern browser.
  useBrowserBuiltins:                           // Include node util modules.
    'useBrowserBuiltins' in argv ?
    argv.useBrowserBuiltins === 'true' :
    defaults.useBrowserBuiltins,
  logTiming: 'logTiming' in argv ?              // Colored timing logs.
    argv.logTiming === 'true' :
    defaults.logTiming,
  sourceMapsType: 'sourceMapsType' in argv ?
    argv.sourceMapsType: defaults.sourceMapsType,
  pageRouteRoot: 'pageRouteRoot' in argv ?
    argv.pageRouteRoot : defaults.pageRouteRoot, // URLs based in this directory
  useSourceMaps: 'useSourceMaps' in argv ?
    argv.useSourceMaps === 'true' :
    defaults.useSourceMaps,                     // Generate client source maps.
  ignorePaths: function(p) {                    // Additional filtering
    return p.indexOf('__tests__') !== -1;
  },
  blacklistRE: argv.blacklistRE && new RegExp(argv.blacklistRE),
  serverRender: 'serverRender' in argv ?
    argv.serverRender === 'true': defaults.serverRender,
  dev: argv.dev === 'true'
};

if (!isServer) {
  reactMiddleware.compute(buildOptions)(argv.computeForPath, function(str) {
    process.stdout.write(str);
  });
} else {
  var app = express();


  equation.add_module( app )  


// map react to main game content
  app.use( '/static', reactMiddleware.provide(buildOptions))
    .use('/static', express.static(__dirname + '/pages'));




  var portToUse = port || 8080;
  http.createServer(app).listen(portToUse);
  console.log('Open http://localhost:' + portToUse + '/index.html');
}
@@ -1,8 +1,603 @@
+/**%0A * Copyright 2013 Facebook, Inc.%0A *%0A * Licensed under the Apache License, Version 2.0 (the %22License%22);%0A * you may not use this file except in compliance with the License.%0A * You may obtain a copy of the License at%0A *%0A * http://www.apache.org/licenses/LICENSE-2.0%0A *%0A * Unless required by applicable law or agreed to in writing, software%0A * distributed under the License is distributed on an %22AS IS%22 BASIS,%0A * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.%0A * See the License for the specific language governing permissions and%0A * limitations under the License.%0A */%0A
 %22use str
@@ -789,98 +789,8 @@
 );%0A%0A
-var equation = require('./modules/equation/module.js')%0A%0Avar express = require('express')%0A%0A
 var 
@@ -889,21 +889,17 @@
 _ROOT, '
-pages
+.
 ');%0A%0Avar
@@ -2795,210 +2795,292 @@
 p = 
-express();%0A%0A%0A  equation.add_module( app )  %0A%0A%0A// map react to main game content%0A  app.use( '/static', reactMiddleware.provide(buildOptions))%0A    .use('/static', express.static(__dirname + '/pages'));%0A%0A%0A
+connect()%0A    .use(reactMiddleware.provide(buildOptions))%0A    .use(connect%5B'static'%5D(FILE_SERVE_ROOT))%0A    .use(connect.favicon(path.join(FILE_SERVE_ROOT, 'elements', 'favicon', 'favicon.ico')))%0A    .use(connect.logger())%0A    .use(connect.compress())%0A    .use(connect.errorHandler());
 %0A%0A  

clean reactjs