jurisv / nodejs.extdirect

Ext.Direct connector for node.js (npm module)
41 stars 16 forks source link

Wrong url is computed at request `/directapi` #36

Closed khusamov closed 7 years ago

khusamov commented 8 years ago

Wrong url is computed at request /directapi

he file api.js need to fix the line 52:

'url': config.relativeUrl ? config.classPath : config.protocol + '://' + config.server + (config.port == '80' ? '' : (':' + config.port)) + config.classPath,

to

'url': config.relativeUrl ? config.classPath : config.protocol + '://' + config.server + (config.port == '80' ? '' : (':' + config.port)) + config.classRouteUrl,
abenhamdine commented 8 years ago

Hmm are you sure ? I use everyday extdirect and I have no problem with the connexion to /directapi, though I never gave a look to the source code.

khusamov commented 8 years ago

Now I had to make these settings:

http://localhost:3000/directapi

{
"url": "http://localhost:3000/app/direct",
"namespace": "Server",
"type": "remoting",
let directConfig = {
    rootNamespace: "Server",
    apiName: "api",
    apiUrl: "/directapi",
    classRouteUrl: "/app/direct",
    classPath: "/app/direct",
    server: "localhost",
    port: "3000",
    ...
};

If I parameter class RouteUrl will set a value: classRouteUrl: "/direct",

That API will not be available at the URL : http://localhost:3000/direct

abenhamdine commented 8 years ago

FWIW, here is my config that works perfectly :

in app/DirectAPI.js

Ext.define('MyApp.DirectAPI', {

    //Require Ext.Direct classes

    requires: ['Ext.direct.*']
}, function() {
    var Loader = Ext.Loader;

    //Loading API
    Loader.loadScriptsSync(['http://localhost:8889/directapi']);

    //Custom implementation. Works only with node backend and extdirect connector v2
    //This feature is part ApiProcessor implementation
    //

    var ns = Server.API;

    if (ns) {
        // Check for unexpected problems
        // Node backend will set error object
        if (ns.error) {
            //This is handled later in Application launch method
            MyApp.DirectError = ns.error;
        } else {
            Ext.direct.Manager.addProvider(ns);
        }
    }
});

in server.js (nodejs main file) :

var directConfig = {
    rootNamespace: "Server",
    apiName: "API",
    apiUrl: "/directapi",
    classRouteUrl: "/direct",
    classPath: "/direct",
    server: "localhost",
    port: "8889",
    protocol: "http",
    timeout: 30000,
    cacheAPI: false,
    relativeUrl: false,
    appendRequestResponseObjects: true,
    enableMetadata: true,
    responseHelper: true,
    enableProcessors: true
};

// ------------------------------------------------
//                   ROUTES
// ------------------------------------------------

//GET method returns API
app.get(directConfig.apiUrl, function(req, res) {
    try {
        directApi.getAPI(
            function(api) {
                res.writeHead(200, {
                    'Content-Type': 'application/json'
                });
                res.end(api);
            }, req, res
        );
    } catch (e) {
        console.log(e);
    }
});
jurisv commented 8 years ago

I will take a look over the week

abenhamdine commented 8 years ago

Ah @khusamov is right, I reproduce the pb now : just set two different paths for classPath and classRouteUrl in directConfig.