 
     load = load_class('Loader', 'core')
     load.initialize @CI, $autoload
-    @app.use load_class('Exceptions',  'core').middleware()
-
-    $render = ($view, $data, $callback) ->
+
+    @app.router.use load_class('Exceptions',  'core').middleware()
+
+    #
+    # create the application window
+    #
+    @window = @app.createWindow(@appjs.url, @appjs.window)
+
+    #
+    # show the window after initialization
+    #
+    @window.on 'create', ->
+      @window.frame.show()
+      @window.frame.center()
+
+    #
+    # add require/process/module to the window global object for debugging from the DevTools
+    #
+    @window.on 'ready', ->
+      @window.require = require
+      @window.process = process
+      @window.module = module
+      @window.addEventListener 'keydown', (e) ->
+        @window.frame.openDevTools()  if e.keyIdentifier is "F12"
+    
+
+  #  --------------------------------------------------------------------
+
+  #
+  # Config registration
+  #
+  #   called by the core/Config class constructor
+  #
+  # @access	public
+  # @param	object $CFG
+  # @return	void
+  #
+  config: ($config) ->
+
+    @appjs = $config['appjs']
+
+
+  #  --------------------------------------------------------------------
+
+  #
+  # Output registration
+  #
+  #   called by the core/Output class constructor
+  #
+  # @access	public
+  # @param	object $OUT
+  # @return	void
+  #
+  output: ($output) ->
+
+    $theme ='default'
+    @assets = APPPATH+"themes/"+$theme+"/assets/"
+    @app.serveFilesFrom @assets
+    #
+    # override the appjs router
+    #
+    appjs.router.handle = ($req, $res) ->
+
+      # Check if this is a request for static content
+      $fullpath = path.join(@assets, $req.pathname)
+      if file_exists($fullpath) and is_file($fullpath)
+        #
+        # Serve static content: *.css, *.js, *.html, etc.
+        #
+        $handle.apply appjs.router, arguments
+      else
+        #
+        # Serve routed virtual content
+        #
+        $req.originalUrl = $req.url
+        $req.url = $req.pathname
+    #$server.handle.apply $server, arguments
+
+    @app.router.use $output.middleware()
+    return
+
+
+  #  --------------------------------------------------------------------
+
+  #
+  # Input registration
+  #
+  #   called by the core/Input class constructor
+  #
+  # @access	public
+  # @param	object $IN
+  # @return	void
+  #
+  input: ($input) ->
+    @app.router.use express.methodOverride()
+    @app.router.use $input.middleware()
+
+
+  #  --------------------------------------------------------------------
+
+  #
+  # URI registration
+  #
+  #   called by the core/URI class constructor
+  #
+  # @access	public
+  # @param	object $IN
+  # @return	void
+  #
+  uri: ($uri) ->
+    @app.router.use $uri.middleware()
+    return
+
+  #  --------------------------------------------------------------------
+
+  #
+  # Sessions registration
+  #
+  #   called by the libraries/Session/Session class constructor
+  #
+  # @access	public
+  # @param	object $IN
+  # @return	void
+  #
+  session: ($session) ->
+    @app.router.use $session.middleware()
+    return
+
+  #  --------------------------------------------------------------------
+
+  #
+  # Upgrade -
+  #
+  #   appjs is similar to connect, so we'll upgrade it here
+  #   such that Exspresso will think it's talking to express.
+  #
+  # @access	public
+  # @return	void
+  #
+  upgrade: ($req, $res, $next) ->
+
+    return $next() if @upgraded # only run once
+    #
+    # Request properties
+    #
+    $req.session = $req.session ? {}
+
+
+    #
+    # Response properties
+    #
+    $res.render = ($view, $data, $callback) ->
 
       fs.readFile $view, 'utf8', ($err, $str) ->
         if $err then $callback($err)

    @CI = get_instance()              # the Exspresso core instance

    @app = require('appjs')

  #  --------------------------------------------------------------------



class global.MY_Server extends CI_Server

  assets:     ''
  options:    null
  window:     null
  appjs:      null
  upgraded:   false
  handle:     null

  constructor: ->

