EzDevInfo.com

pencilblue

A full featured Node.js CMS and blogging platform (plugins, server cluster management, data-driven pages) PencilBlue pencilblue is the only node.js cms and blogging platform to meet all the needs of a modern website.

Pencilblue: Building api around custom object type

I'm trying to build an API using pencilblue, but can't figure out how to start. This question is really wide but I'm looking for examples on creating CRUD API with custom object.

Thanks!


Source: (StackOverflow)

Pencilblue - origin not allowed for controller endpont

I'm developing an API using pencilblue, everything works fine until I make an AJAX request to this endpoint.

I always get an "origin not allowed" error.

Is there a way to enable CORS with pencilblue?


Source: (StackOverflow)

Advertisements

PencilBlue - Custom Object Id's

I'm working with PencilBlue, and I'm having trouble with the custom objects Id's. The "name" field is used as an Id, but I would like it to be just a regular field and have an "id" field as identifier.

How could I achieve this?


Source: (StackOverflow)

Pencilblue - RequestHandler: An error occurred during controller execution

I've been struggling here with this for a while now. I would like to get articles from my PencilBlue database using a controller. I'm using the "sample" plugin as a base.

The problem is that whenever I hit my GET /api/articles endpoint, I get an error saying that something is not a function.

This is the code I have so far:

module.exports = function BookApiControllerModule(pb) {

  //PB dependencies
  var util = pb.util;
  var BaseApiController = pb.BaseApiController;
  var PluginService = pb.PluginService;
  var BaseObjectService = pb.BaseObjectService;
  var BookService = PluginService.getService('BookService', 'articles-api');
  var ArticleService = pb.ArticleService;
  var TYPE = 'article';

  //Creating an inline service.
  function DndService(context) {
    if (!util.isObject(context)) {
      context = {};
    }
    context.type = TYPE;
    DndService.super_.call(this, context);
  }

  util.inherits(DndService, BaseObjectService);

  DndService.getName = function () {
    return "DndService";
  }

  DndService.getArticles = function (ctx, cb) {
    ctx.data = {message: "ASDF"};
    cb(null);
  };

  BaseObjectService.on(TYPE + '.' + BaseObjectService.GET_ALL, DndService.getArticles);
  //Done with the inline service

  function BookApiController() {
    this.service = new DndService();
  };
  util.inherits(BookApiController, pb.BaseApiController);

  BookApiController.getRoutes = function (cb) {
    var routes = [
      {
        method: 'get',
        path: "/api/articles",
        handler: "getArticles",
        content_type: 'application/json'
      }
    ];
    cb(null, routes);
  };

  //exports
  return BookApiController;
};

And this is the error I get:

RequestHandler: An error occurred during controller execution. URL=[GET:/api/articles] ROUTE={"path":"api/articles","pattern":"^/api/articles[/]{0,1}$","path_vars":{},"expression":{},"themes":{"articles-api":{"GET":{"method":"GET","path":"/api/articles","handler":"getArticles","content_type":"application/json"}}}}
TypeError: undefined is not a function
    at /Users/danielrvt/IdeaProjects/article-test/include/http/request_handler.js:869:79
    at process._tickDomainCallback (node.js:381:11)

Source: (StackOverflow)

Pencilblue - Webservice to get a list of all articles rendered

I was wondering if there is a way to get a list of all article's HTML already rendered. I want the media image files rendered as <img> and not as a ^media_display_55aabd2ac89b5e44211ccf86/position:none^.

I've built a controller for this:

module.exports = function BookApiControllerModule(pb) {

  //PB dependencies
  var util = pb.util;
  var BaseApiController = pb.BaseApiController;
  var PluginService = pb.PluginService;
  var BaseObjectService = pb.BaseObjectService;
  var BookService = PluginService.getService('BookService', 'articles-api');
  var ArticleService = pb.ArticleService;
  var TYPE = 'article';

  //Creating an inline service.
  function DndService(context) {
    if (!util.isObject(context)) {
      context = {};
    }
    context.type = TYPE;
    DndService.super_.call(this, context);
  }

  util.inherits(DndService, BaseObjectService);

  DndService.getName = function () {
    return "DndService";
  };

  DndService.init = function (cb) {
    pb.log.debug("DndService: Initialized");
    cb(null, true);
  };

  DndService.beforeSave = function (context, cb) {
    cb(null);
  };

  DndService.afterSave = function (context, cb) {
    cb(null);
  };

  DndService.beforeDelete = function (context, cb) {
    cb(null);
  };

  DndService.afterDelete = function (context, cb) {
    cb(null);
  };

  DndService.validate = function (context, cb) {
    cb(null);
  };

  DndService.merge = function (context, cb) {
    cb(null);
  };

  DndService.format = function (context, cb) {
    cb(null);
  };

  DndService.getAll = function (ctx, cb) {
    ctx.data = [{message: "ASDF"}];
    cb(null);
  };

  BaseObjectService.on(TYPE + '.' + BaseObjectService.GET_ALL, DndService.getAll);
  //Done with the inline service

  function BookApiController() {
    this.service = new DndService();
  };
  util.inherits(BookApiController, pb.BaseApiController);

  BookApiController.getRoutes = function (cb) {
    var routes = [
      {
        method: 'get',
        path: "/api/articles",
        handler: "getAll",
        content_type: 'application/json'
      }
    ];
    cb(null, routes);
  };

  //exports
  return BookApiController;
};

And it returns the following:

{
    "data": [
        {
            "_id": "55c2a7650668d47274859fc8",
            "author": "55aaa75a3bb0fbbd2056c76d",
            "publish_date": "2015-08-05T22:45:00.000Z",
            "meta_keywords": [
                ""
            ],
            "article_media": [
                "55aabd2ac89b5e44211ccf86",
                "55c2a86d0668d47274859fd1"
            ],
            "article_sections": [],
            "article_topics": [],
            "headline": "wefghj",
            "subheading": "khgvhjvgjvgh",
            "url": "blahhhhh",
            "draft": 0,
            "article_layout": "^media_display_55aabd2ac89b5e44211ccf86/position:none^^media_display_55c2a86d0668d47274859fd1/position:none^",
            "object_type": "article",
            "created": "2015-08-06T00:16:37.889Z",
            "last_modified": "2015-08-06T00:22:46.825Z",
            "id": "55c2a7650668d47274859fc8",
            "template": "pencilblue|index"
        }
    ],
    "total": 1,
    "count": 1,
    "offset": 0,
    "limit": 1000
}

Source: (StackOverflow)

Mongolab connecting to Heroku with PencilBlue

I have small issue and I don't know where to start: I have application error and I think my MongoLab database is not connecting correctly.

Here is link to heroku w2w.

An error occurred in the application and your page could not be served. Please try again in a few moments.

If you are the application owner, check your logs for details.

And here is my config.json file:

{
"siteName": "PencilBlue Heroku and MongoDB Demo",
"siteRoot": "http://w2w.herokuapp.com",
"siteIP": "w2w.herokuapp.com",
"log_level": "info",
"db": {
    "type":"mongo",
    "servers": [
    "mongodb://hercules:MYPASSWORD@ds063330.mongolab.com:63330/pencilbluedb"
    ],
    "name": "pencilbluedb",
    "authentication": {
        "un": "hercules",
        "pw": "MYPASSWORD",
    },
    "writeConern": 1
},
"cache": {
    "fake": true,
    "host": "localhost",
    "port": 6379
},
"settings": {
    "use_memory": true,
    "use_cache": false
},
"templates": {
    "use_memory": true,
    "use_cache": false
},
"plugins": {
    "caching": {
        "use_memory": true,
        "use_cache": false
    }
}
} 

I have no idea why it's not loading. I followed the instructions here: Pencilblue link, the only difference is that I'm trying to connect to MongoLab and they are suggesting MongoHQ (which has already been changed to "compose").

Any help would be appreciated.


Source: (StackOverflow)

How to add a module to Angular in Pencilblue?

So I'm building this Pencilblue website. Pencilblue is based on the MEAN stack.

I'm trying to get a search function going. I need to declare a module.

Pencilblue does it like this:

ClientJs.getAngularController = function(objects, modules, directiveJS) {
    if(!util.isArray(modules) || modules.length > 0) {
        modules = ['ngRoute'];
    }

    var angularController = 'var pencilblueApp = angular.module("pencilblueApp", ' + JSON.stringify(modules) + ')';

So the 2nd line is telling me the modules are loaded from somewhere else, unless there are none, in which case, the modules = ['ngRoute']; should be loaded.

What I came up with is this:

ClientJs.getAngularController = function(objects, modules, directiveJS) {
        if( modules.length > 0) {
            modules = ['ngRoute', 'elasticui'];
        }

        var angularController = "var pencilblueApp = angular.module('pencilblueApp', " + JSON.stringify(modules) + ").constant('euiHost', 'localhost:9200')";

While this works, I'm not sure it's an orthodox way of doing it and I might need to add others in the future. I'd really appreciate if someone could help out and tell me the right way to add this ['elasticui'] module in Pencilblue, together with the last part, the .constant('euiHost', 'localhost:9200')";

I'm adding ElasticUI to my project, and the only thing that I had problems with was adding this step: angular.module('yourApp', ['elasticui']).constant('euiHost', 'http://localhost:9200');

It's rather trivial to do it in a MEAN stack or plain Angular.js, but it's quite confusing in Pencilblue.

Would really appreciate a detailed response on how to do this the proper way. Thanks.


Source: (StackOverflow)