Skip to content

Latest commit

 

History

History
 
 

cheesecakes

Cheesecakes demo application

In this application you will see how to

  • Use filters with routes generated by the Content Type Builder
  • Create custom routes / controllers / services.
  • Use groups and authentication permissions

Setup

1 — Clone the repository.

git clone git@github.com:strapi/strapi-examples.git

2 — Go to the cheesecakes example and install the dependencies.

cd cheesecakes
npm install
npm run setup --plugins
# It take few minutes

3 — Install MongoDB.

4 — Start a MongoDB server.

mongod

5 — Start the cheesecakes server.

npm start

4 — Update permissions.

You have to go in your admin panel and update permission of the Public role (Plugins > Users & Permissions > Public).

Allow these actions:

  • App:
    • Info
  • Cake:
    • Count
    • Find
    • FindOne
  • Category:
    • Find
    • FindOne
  • Review:
    • Submit
    • Find
    • FindOne

Bootstrap application data

When you start your application for the first time, if you don't have any data, we auto inject a dataset in your mongo database. You can see how we did it in the /config/function/bootstrap.js file. It calls the initDatabase function of the /api/app/service/App.js service's file. The dataset is in /api/app/config/data.json.

Rendering views

When you are at http://localhost:1337, Strapi renders the /public/index.html file. In this file we inject /public/css/style.css and /public/scripts/index.js. When you click on a cheesecake item, Strapi renders public/product.html. Documentation link https://strapi.io/documentation/guides/public-assets.html.

Filters

In the /public/scripts/index.js you will see how to make a GET request using filter params on cakes. API endpoints are located at /api/cake/config/routes.json. Documentation link https://strapi.io/documentation/guides/filters.html.

Custom route

By default the Content Type Builder doesn't provide a route to count data. So we create a new route in /api/cake/config/routes.json GET /cake/count. We have to put this route just before GET /cake/:_id. Then you have to create the associated controller's function and also in this particular case we have to create a service.

Authentication

In public/product.html page we add login / register function to be able to submit a review. At the end of the /public/scripts/product.js file you will see how use auth routes. Documentation link https://strapi.io/documentation/guides/authentification.html.

Admin

In the admin panel (http://localhost:1337/admin) you will be able to manage (create/update/delete) cakes.