Giter VIP home page Giter VIP logo

Comments (4)

nazirov91 avatar nazirov91 commented on June 29, 2024

@devalexandre

  • Make sure CORS is enabled in Strapi project
  • Add Content-Range to expose headers object in <your_project>/config/environments/development/security.js
"cors": {
    "enabled": true,
    "origin": "*",
    "expose": [
      "WWW-Authenticate",
      "Server-Authorization",
      "Content-Range" // <<--- HERE
    ],
    ...
  },
  ...
}

from ra-strapi-rest.

nazirov91 avatar nazirov91 commented on June 29, 2024

or if you are using the Strapi Beta version, you need to override the find method for Products controller

// api/post/controllers/Products.js

'use strict';
const { sanitizeEntity } = require('strapi-utils');

module.exports = {
  async find(ctx) {
    let entities;
    ctx.set('Content-Range', await strapi.services.product.count()); // <--- Don't forget this guy
    if (ctx.query._q) {
      entities = await strapi.services.product.search(ctx.query);
    } else {
      entities = await strapi.services.product.find(ctx.query);
    }

    return entities.map(entity =>
      sanitizeEntity(entity, { model: strapi.models.product })
    );
  },
};

from ra-strapi-rest.

devalexandre avatar devalexandre commented on June 29, 2024

when I alter controll display it

 Server wasn't able to start properly.
[2020-03-17T01:57:46.570Z] error TypeError: Cannot read property 'bind' of undefined
    at routerChecker (/Users/alexandre/projetos/cardapio-online/backend/node_modules/strapi/lib/middlewares/router/utils/routerChecker.js:35:43)
    at /Users/alexandre/projetos/cardapio-online/backend/node_modules/strapi/lib/middlewares/router/utils/composeEndpoint.js:15:52
    at /Users/alexandre/projetos/cardapio-online/backend/node_modules/strapi/lib/middlewares/router/index.js:25:9
    at arrayEach (/Users/alexandre/projetos/cardapio-online/backend/node_modules/lodash/lodash.js:516:11)
    at Function.forEach (/Users/alexandre/projetos/cardapio-online/backend/node_modules/lodash/lodash.js:9342:14)
    at Object.initialize (/Users/alexandre/projetos/cardapio-online/backend/node_modules/strapi/lib/middlewares/router/index.js:24:9)
    at /Users/alexandre/projetos/cardapio-online/backend/node_modules/strapi/lib/middlewares/index.js:43:28
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

from ra-strapi-rest.

nazirov91 avatar nazirov91 commented on June 29, 2024

when I alter controll display it

 Server wasn't able to start properly.
[2020-03-17T01:57:46.570Z] error TypeError: Cannot read property 'bind' of undefined
    at routerChecker (/Users/alexandre/projetos/cardapio-online/backend/node_modules/strapi/lib/middlewares/router/utils/routerChecker.js:35:43)
    at /Users/alexandre/projetos/cardapio-online/backend/node_modules/strapi/lib/middlewares/router/utils/composeEndpoint.js:15:52
    at /Users/alexandre/projetos/cardapio-online/backend/node_modules/strapi/lib/middlewares/router/index.js:25:9
    at arrayEach (/Users/alexandre/projetos/cardapio-online/backend/node_modules/lodash/lodash.js:516:11)
    at Function.forEach (/Users/alexandre/projetos/cardapio-online/backend/node_modules/lodash/lodash.js:9342:14)
    at Object.initialize (/Users/alexandre/projetos/cardapio-online/backend/node_modules/strapi/lib/middlewares/router/index.js:24:9)
    at /Users/alexandre/projetos/cardapio-online/backend/node_modules/strapi/lib/middlewares/index.js:43:28
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

Is it happening only when you modify the controller?

Have you tried this option: strapi/strapi#4042

from ra-strapi-rest.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.