Results 1 to 5 of 5

Thread: Running Ext.Direct Backend in Node.js using Passenger

  1. #1
    Sencha User
    Join Date
    Nov 2009
    Aveiro, Portugal

    Default Running Ext.Direct Backend in Node.js using Passenger


    I've followed Juris's blog entry Writing an Ext.Direct Backend in Node.js and I wrote a small application ( I've added some logic for user authentication, PostgreSQL and OpenLayers + GeoEXT2.

    Everything runs fine if I start the application from the command line:
    nodemon server.js
    and the application is available from: http://localhost:3000/

    I would like to deploy it to a server already running Apache. I've installed Fusion Passenger, and created the VirtualHost entry, that reads:

    <VirtualHost *:80>
            ServerName development.localhost.lan
    #       DocumentRoot /home/jgr/git/extdirect.examples/node-server/extdirect-pg/public
            DocumentRoot /home/jgr/git/extdirect.examples/client/DemoExtJs
            PassengerAppRoot /home/jgr/git/extdirect.examples/node-server/extdirect-pg
    I even separated the DocumentRoot and the AppRoot (because public was a link to the client application).

    When I try to run the application from Apache+Passenger, it starts the application, but immediately fails when trying to fetch:

    GET http://development.localhost.lan/dir...=1403100801391 404 (Not Found)

    Passenger starts the application. Passenger should know which requests are to the client and which request are to the server, right? So, this path (/directapi) should be handled by express in server.js, I think.

    //GET method returns API
    app.get(ExtDirectConfig.apiPath, function(request, response) {
    My server-config.json is configured like:

        "ServerConfig": {
            "port": 3000,
            "logger": "dev",
            "enableUpload": true,
            "enableCompression": true,
            "webRoot": "/public",
            "fileUploadFolder": "./uploads",
            "enableSessions": true,
            "sessionSecret": "fe80::227:10ff:fe7e:fcb4",
            "enableCORS": true,
            "AccessControlAllowOrigin": "*",
            "AccessControlAllowMethods": "GET,PUT,POST,DELETE,OPTIONS",
            "AccessControlAllowHeaders": "Origin, X-Requested-With, Content-Type, Accept",
            "AccessControlAllowCredentials": true,
            "AccessControlMaxAge": 3600
        "ExtDirectConfig": {
            "namespace": "ExtRemote",
            "apiName": "REMOTING_API",
            "apiPath": "/directapi",
            "classPath": "/direct",
            "classPrefix": "DX",
            "server": "development.localhost.lan",
            "port": "3000",
            "protocol": "http",
            "relativeUrl": true,      
            "appendRequestResponseObjects": true
    The DirectAPI.js loads the API with
    Loader.loadScriptFile('directapi', Ext.emptyFn, Ext.emptyFn, null, true);
    Any help for experienced users is appreciated, since I'm not able to identify if this is a Passenger configuration issue or a node/ issue.

    Thanks in advance.

  2. #2
    Sencha User
    Join Date
    Nov 2009
    Aveiro, Portugal

    Default extdirect.processRoute


    It seems that the problem is related to the following code in server.js:
    // POST request process route and calls class, function(request, response) {
    	extdirect.processRoute(request, response, ExtDirectConfig);
    Posts to the API are not properly routed:
    POST http://development.localhost.lan/direct 500 (Internal Server Error)
    The error is:

    Error: Cannot find module '/usr/share/passenger/helper-scripts/direct/DXTree'    at Function.Module._resolveFilename (module.js:338:15)    at Function.Module._load (module.js:280:25)    at Module.require (module.js:364:17)    at require (module.js:380:17)    at Object.route.processRoute (/home/jgr/git/extdirect.examples/node-server/extdirect-pg/node_modules/extdirect/lib/router.js:94:17)    at (/home/jgr/git/extdirect.examples/node-server/extdirect-pg/server.js:146:12)    at callbacks (/home/jgr/git/extdirect.examples/node-server/extdirect-pg/node_modules/express/lib/router/index.js:161:37)    at param (/home/jgr/git/extdirect.examples/node-server/extdirect-pg/node_modules/express/lib/router/index.js:135:11)    at pass (/home/jgr/git/extdirect.examples/node-server/extdirect-pg/node_modules/express/lib/router/index.js:142:5)    at Router._dispatch (/home/jgr/git/extdirect.examples/node-server/extdirect-pg/node_modules/express/lib/router/index.js:170:5)
    I took a look at node_modules/extdirect/lib/router.js and I found onw thing that my cause problems.

    var vPath = require('path');
    var route = {
        processRoute : function(req, resp, config){
            var root = vPath.dirname(process.mainModule.filename),
    This process.mainModule.filename returns different paths, if I run the application directly with node or with passenger.

    With node: /home/jgr/git/extdirect.examples/node-server/extdirect-pg
    With Passenger: /usr/share/passenger/helper-scripts

    Changing this path to the correct one (static path hard coded) fixed this problem.

    To fix the problem of loading /directapi, I created a javascript file on the client side (i public) with the API within.

    So, instead of:
    Loader.loadScriptFile('/directapi', Ext.emptyFn, Ext.emptyFn, null, true);
    I put:
    Loader.loadScriptFile('/ppgis.js', Ext.emptyFn, Ext.emptyFn, null, true);

    This is too much fixing. Giving up on Passenger for now...

  3. #3
    Sencha User
    Join Date
    Nov 2009
    Aveiro, Portugal

    Default Problem solved


    I took a look at Juris's code and I was able to fix the routing either when the application runs from node or from Apache+Passenger. Now /directapi and /direct calls are resolved.
    I've made a pull request with my two cents to solve the problem.


  4. #4
    Sencha User
    Join Date
    Dec 2010
    GMT+1 - DST+1

    Default Cannot read property 'extAction' of undefined

    I don't want to open an new thead. My problem belongs almost to the same topic.

    While my direct POST is running, it got no 'request.body' data in processRoute() [router.js],
    which lead to the error message:
    TypeError: Cannot read property 'extAction' of undefined.

    Appreciating any hints.

    Btw.: which node.js version is necessary to run this extdirect backend ? (I got v0.10.31)

  5. #5
    Sencha - Services Team Stju's Avatar
    Join Date
    Dec 2008
    Redwood city, California


    A little bit late response but it might help others.
    The problem you were observing is du to the fact that Express framework changed the way how the middleware is being included, thus you have to add bodyParser separately and tel that you want JSON to be decoded:

    // parse application/x-www-form-urlencoded
    app.use(bodyParser.urlencoded({ extended: true }));
    // parse application/json
    N.B. New examples for node.js are released that address the aforementioned problem as well as version 2 of connector.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts