demo/README.rst
author Frank Bessou <frank.bessou@logilab.fr>
Tue, 04 Apr 2017 17:00:42 +0200
changeset 79 1070e0148bd8
parent 67 830a5ff5bdc2
child 83 2aac210e9a15
permissions -rw-r--r--
Render actions in EntitiesView

Setting up a demo instance
==========================

Server setup
------------

* create a Python `virtualenv` and activate it

* install ``cubicweb-jsonschema`` from
  http://hg.logilab.org/master/cubicweb-jsonschema, either by installing from
  a local checkout or as:

  ::

      pip install hg+http://hg.logilab.org/master/cubicweb-jsonschema#egg=cubicweb-jsonschema

* install the ``demo/server`` package as ``pip install [-e] demo/server``
  (this is actually a CubicWeb cube with a "bookstore" data model that we pull
  a recent CubicWeb version)

* create an ``jsonschema-demo`` instance of the ``bookstore`` cube with a
  ``pyramid`` configuration type

  ::

      cubicweb-ctl create -c pyramid bookstore jsonschema-demo

* in order to avoid any authorization issues, you might want to set
  ``anonymous-user`` and ``anonymous-password`` options in ``pyramid.conf``
  file in the CubicWeb instance directory to use a priviledged user (such as
  ``admin``)

* start the server with:

  ::

      pserve <path to jsonschema-demo instance>/development.ini

* try out:

  ::

      http :6543/schema Accept:application/schema+json

  you should get something like:

  ::

      HTTP/1.1 200 OK
      Content-Length: 455
      Content-Type: application/json
      Date: Fri, 24 Mar 2017 08:23:50 GMT
      Server: waitress

      {
          "links": [
              {
                  "description": "List authors",
                  "href": "/author/",
                  "method": "GET",
                  "rel": "instances",
                  "targetSchema": {
                      "$ref": "/author/schema"
                  },
                  "title": "List"
              },
              {
                  "description": "List books",
                  "href": "/book/",
                  "method": "GET",
                  "rel": "instances",
                  "targetSchema": {
                      "$ref": "/book/schema"
                  },
                  "title": "List"
              },
              {
                  "description": "List topics",
                  "href": "/topic/",
                  "method": "GET",
                  "rel": "instances",
                  "targetSchema": {
                      "$ref": "/topic/schema"
                  },
                  "title": "List"
              }
          ]
      }

Client setup
------------

* To run the client interface embedded into the server process add
  ``cubicweb_bookstore.pviews`` to the ``pyramid.include`` configuration
  option of the ``development.ini`` file in you demo instance directory.

* To run the client into its own node server run ``npm start``.
  The jsonschema api's URL can be set with the ``API_URL`` environment variable:

  ::

     API_URL=http://localhost:12345 npm start

  Your CubicWeb instance must be configured to allow requests coming from the client interface and
  to allow the client to read ``Allow`` headers in responses.
  One way of doing this is by adding a cors filter in the ``development.ini`` file, for example:


  ::

      [pipeline:main]
      pipeline =
        cors
        myapp

      [filter:cors]
        use = egg:wsgicors#middleware
        policy=free
        free_origin=*
        free_headers=*
        free_expose_headers=Allow
        free_methods=HEAD, OPTIONS, GET, POST, PATCH, PUT, DELETE
        free_maxage=180

      [app:myapp]
      ...