Sailsjs + Ext-direct (sencha Extjs)
I was wondering if anyone has used ext-direct with sailsjs. If you have or anyone with the know how, please can you direct me. Thank you. Here are some examples In regular nodejs
Solution 1:
The simplest way to do this would be using the customMiddleware
config option of Sails. This option allows you to supply a function that will receive the underlying Express app as its sole argument, to which you can add your own routes or middleware. Find or create your config/express.js file and put in something like this:
// First, do all requires / setup necessary so that // `extdirect` and `ExtDirectConfig` exist, then:module.exports.express = {
customMiddleware: function(app) {
app.get(ExtDirectConfig.apiPath, function (request, response) {
try {
var api = extdirect.getAPI(ExtDirectConfig);
response.writeHead(200, {'Content-Type': 'application/json'});
response.end(api);
} catch (e) {
console.log(e);
}
});
// Ignoring any GET requests on class path
app.get(ExtDirectConfig.classPath, function (request, response) {
response.writeHead(200, {'Content-Type': 'application/json'});
response.end(JSON.stringify({success: false, msg: 'Unsupported method. Use POST instead.'}));
});
// POST Request process route and calls class
app.post(ExtDirectConfig.classPath, db, function (request, response) {
extdirect.processRoute(request, response, ExtDirectConfig);
});
}
}
A more involved, but ultimately more re-usable strategy would be to create a custom "hook", or Sails plugin, for ExtDirect. Documentation for custom hooks is in development here.
Post a Comment for "Sailsjs + Ext-direct (sencha Extjs)"