diff --git a/examples/getstarted/src/api/category/controllers/category.js b/examples/getstarted/src/api/category/controllers/category.js new file mode 100644 index 0000000000..33db063f98 --- /dev/null +++ b/examples/getstarted/src/api/category/controllers/category.js @@ -0,0 +1,5 @@ +'use strict'; + +const { createCoreController } = require('@strapi/strapi').factories; + +module.exports = createCoreController('api::category.category'); diff --git a/examples/getstarted/src/api/category/routes/category.js b/examples/getstarted/src/api/category/routes/category.js index b2165a4a17..eb65fc52c0 100755 --- a/examples/getstarted/src/api/category/routes/category.js +++ b/examples/getstarted/src/api/category/routes/category.js @@ -1,46 +1,5 @@ 'use strict'; -module.exports = { - routes: [ - { - method: 'GET', - path: '/categories', - handler: 'category.find', - config: { - policies: [], - }, - }, - { - method: 'GET', - path: '/categories/:id', - handler: 'category.findOne', - config: { - policies: [], - }, - }, - { - method: 'POST', - path: '/categories', - handler: 'category.create', - config: { - policies: [], - }, - }, - { - method: 'PUT', - path: '/categories/:id', - handler: 'category.update', - config: { - policies: [], - }, - }, - { - method: 'DELETE', - path: '/categories/:id', - handler: 'category.delete', - config: { - policies: [], - }, - }, - ], -}; +const { createCoreRouter } = require('@strapi/strapi').factories; + +module.exports = createCoreRouter('api::category.category'); diff --git a/examples/getstarted/src/api/category/services/category.js b/examples/getstarted/src/api/category/services/category.js new file mode 100644 index 0000000000..92dbe89f07 --- /dev/null +++ b/examples/getstarted/src/api/category/services/category.js @@ -0,0 +1,5 @@ +'use strict'; + +const { createCoreService } = require('@strapi/strapi').factories; + +module.exports = createCoreService('api::category.category'); diff --git a/examples/getstarted/src/api/country/controllers/country.js b/examples/getstarted/src/api/country/controllers/country.js new file mode 100644 index 0000000000..17a50756f6 --- /dev/null +++ b/examples/getstarted/src/api/country/controllers/country.js @@ -0,0 +1,5 @@ +'use strict'; + +const { createCoreController } = require('@strapi/strapi').factories; + +module.exports = createCoreController('api::country.country'); diff --git a/examples/getstarted/src/api/country/routes/country.js b/examples/getstarted/src/api/country/routes/country.js index 6f36b123b2..a1492e2eac 100755 --- a/examples/getstarted/src/api/country/routes/country.js +++ b/examples/getstarted/src/api/country/routes/country.js @@ -1,46 +1,5 @@ 'use strict'; -module.exports = { - routes: [ - { - method: 'GET', - path: '/countries', - handler: 'country.find', - config: { - policies: [], - }, - }, - { - method: 'GET', - path: '/countries/:id', - handler: 'country.findOne', - config: { - policies: [], - }, - }, - { - method: 'POST', - path: '/countries', - handler: 'country.create', - config: { - policies: [], - }, - }, - { - method: 'PUT', - path: '/countries/:id', - handler: 'country.update', - config: { - policies: [], - }, - }, - { - method: 'DELETE', - path: '/countries/:id', - handler: 'country.delete', - config: { - policies: [], - }, - }, - ], -}; +const { createCoreRouter } = require('@strapi/strapi').factories; + +module.exports = createCoreRouter('api::country.country'); diff --git a/examples/getstarted/src/api/country/services/country.js b/examples/getstarted/src/api/country/services/country.js new file mode 100644 index 0000000000..882e7c12f2 --- /dev/null +++ b/examples/getstarted/src/api/country/services/country.js @@ -0,0 +1,5 @@ +'use strict'; + +const { createCoreService } = require('@strapi/strapi').factories; + +module.exports = createCoreService('api::country.country'); diff --git a/examples/getstarted/src/api/homepage/controllers/homepage.js b/examples/getstarted/src/api/homepage/controllers/homepage.js new file mode 100644 index 0000000000..0beed55b73 --- /dev/null +++ b/examples/getstarted/src/api/homepage/controllers/homepage.js @@ -0,0 +1,5 @@ +'use strict'; + +const { createCoreController } = require('@strapi/strapi').factories; + +module.exports = createCoreController('api::homepage.homepage'); diff --git a/examples/getstarted/src/api/homepage/routes/homepage.js b/examples/getstarted/src/api/homepage/routes/homepage.js index 71e73a2616..75b218d090 100644 --- a/examples/getstarted/src/api/homepage/routes/homepage.js +++ b/examples/getstarted/src/api/homepage/routes/homepage.js @@ -1,30 +1,5 @@ 'use strict'; -module.exports = { - routes: [ - { - method: 'GET', - path: '/homepage', - handler: 'homepage.find', - config: { - policies: [], - }, - }, - { - method: 'PUT', - path: '/homepage', - handler: 'homepage.update', - config: { - policies: [], - }, - }, - { - method: 'DELETE', - path: '/homepage', - handler: 'homepage.delete', - config: { - policies: [], - }, - }, - ], -}; +const { createCoreRouter } = require('@strapi/strapi').factories; + +module.exports = createCoreRouter('api::homepage.homepage'); diff --git a/examples/getstarted/src/api/homepage/services/homepage.js b/examples/getstarted/src/api/homepage/services/homepage.js new file mode 100644 index 0000000000..1463a6abcc --- /dev/null +++ b/examples/getstarted/src/api/homepage/services/homepage.js @@ -0,0 +1,5 @@ +'use strict'; + +const { createCoreService } = require('@strapi/strapi').factories; + +module.exports = createCoreService('api::homepage.homepage'); diff --git a/examples/getstarted/src/api/kitchensink/controllers/kitchensink.js b/examples/getstarted/src/api/kitchensink/controllers/kitchensink.js new file mode 100644 index 0000000000..b98fd8ada5 --- /dev/null +++ b/examples/getstarted/src/api/kitchensink/controllers/kitchensink.js @@ -0,0 +1,5 @@ +'use strict'; + +const { createCoreController } = require('@strapi/strapi').factories; + +module.exports = createCoreController('api::kitchensink.kitchensink'); diff --git a/examples/getstarted/src/api/kitchensink/routes/kitchensink.js b/examples/getstarted/src/api/kitchensink/routes/kitchensink.js index 4825e9d9aa..d6b4c6d7e8 100644 --- a/examples/getstarted/src/api/kitchensink/routes/kitchensink.js +++ b/examples/getstarted/src/api/kitchensink/routes/kitchensink.js @@ -1,46 +1,5 @@ 'use strict'; -module.exports = { - routes: [ - { - method: 'GET', - path: '/kitchensinks', - handler: 'kitchensink.find', - config: { - policies: [], - }, - }, - { - method: 'GET', - path: '/kitchensinks/:id', - handler: 'kitchensink.findOne', - config: { - policies: [], - }, - }, - { - method: 'POST', - path: '/kitchensinks', - handler: 'kitchensink.create', - config: { - policies: [], - }, - }, - { - method: 'PUT', - path: '/kitchensinks/:id', - handler: 'kitchensink.update', - config: { - policies: [], - }, - }, - { - method: 'DELETE', - path: '/kitchensinks/:id', - handler: 'kitchensink.delete', - config: { - policies: [], - }, - }, - ], -}; +const { createCoreRouter } = require('@strapi/strapi').factories; + +module.exports = createCoreRouter('api::kitchensink.kitchensink'); diff --git a/examples/getstarted/src/api/kitchensink/services/kitchensink.js b/examples/getstarted/src/api/kitchensink/services/kitchensink.js new file mode 100644 index 0000000000..20954fd232 --- /dev/null +++ b/examples/getstarted/src/api/kitchensink/services/kitchensink.js @@ -0,0 +1,5 @@ +'use strict'; + +const { createCoreService } = require('@strapi/strapi').factories; + +module.exports = createCoreService('api::kitchensink.kitchensink'); diff --git a/examples/getstarted/src/api/like/controllers/like.js b/examples/getstarted/src/api/like/controllers/like.js new file mode 100644 index 0000000000..2e38228f3c --- /dev/null +++ b/examples/getstarted/src/api/like/controllers/like.js @@ -0,0 +1,5 @@ +'use strict'; + +const { createCoreController } = require('@strapi/strapi').factories; + +module.exports = createCoreController('api::like.like'); diff --git a/examples/getstarted/src/api/like/routes/like.js b/examples/getstarted/src/api/like/routes/like.js index b7629cb17d..3de1763a25 100755 --- a/examples/getstarted/src/api/like/routes/like.js +++ b/examples/getstarted/src/api/like/routes/like.js @@ -1,46 +1,5 @@ 'use strict'; -module.exports = { - routes: [ - { - method: 'GET', - path: '/likes', - handler: 'like.find', - config: { - policies: [], - }, - }, - { - method: 'GET', - path: '/likes/:id', - handler: 'like.findOne', - config: { - policies: [], - }, - }, - { - method: 'POST', - path: '/likes', - handler: 'like.create', - config: { - policies: [], - }, - }, - { - method: 'PUT', - path: '/likes/:id', - handler: 'like.update', - config: { - policies: [], - }, - }, - { - method: 'DELETE', - path: '/likes/:id', - handler: 'like.delete', - config: { - policies: [], - }, - }, - ], -}; +const { createCoreRouter } = require('@strapi/strapi').factories; + +module.exports = createCoreRouter('api::like.like'); diff --git a/examples/getstarted/src/api/like/services/like.js b/examples/getstarted/src/api/like/services/like.js new file mode 100644 index 0000000000..be483e3e27 --- /dev/null +++ b/examples/getstarted/src/api/like/services/like.js @@ -0,0 +1,5 @@ +'use strict'; + +const { createCoreService } = require('@strapi/strapi').factories; + +module.exports = createCoreService('api::like.like'); diff --git a/examples/getstarted/src/api/menu/controllers/menu.js b/examples/getstarted/src/api/menu/controllers/menu.js new file mode 100644 index 0000000000..88eaf69238 --- /dev/null +++ b/examples/getstarted/src/api/menu/controllers/menu.js @@ -0,0 +1,5 @@ +'use strict'; + +const { createCoreController } = require('@strapi/strapi').factories; + +module.exports = createCoreController('api::menu.menu'); diff --git a/examples/getstarted/src/api/menu/routes/menu.js b/examples/getstarted/src/api/menu/routes/menu.js index 9ddb6f6479..d351181e59 100755 --- a/examples/getstarted/src/api/menu/routes/menu.js +++ b/examples/getstarted/src/api/menu/routes/menu.js @@ -1,46 +1,5 @@ 'use strict'; -module.exports = { - routes: [ - { - method: 'GET', - path: '/menus', - handler: 'menu.find', - config: { - policies: [], - }, - }, - { - method: 'GET', - path: '/menus/:id', - handler: 'menu.findOne', - config: { - policies: [], - }, - }, - { - method: 'POST', - path: '/menus', - handler: 'menu.create', - config: { - policies: [], - }, - }, - { - method: 'PUT', - path: '/menus/:id', - handler: 'menu.update', - config: { - policies: [], - }, - }, - { - method: 'DELETE', - path: '/menus/:id', - handler: 'menu.delete', - config: { - policies: [], - }, - }, - ], -}; +const { createCoreRouter } = require('@strapi/strapi').factories; + +module.exports = createCoreRouter('api::menu.menu'); diff --git a/examples/getstarted/src/api/menu/services/menu.js b/examples/getstarted/src/api/menu/services/menu.js new file mode 100644 index 0000000000..732b9a6bf3 --- /dev/null +++ b/examples/getstarted/src/api/menu/services/menu.js @@ -0,0 +1,5 @@ +'use strict'; + +const { createCoreService } = require('@strapi/strapi').factories; + +module.exports = createCoreService('api::menu.menu'); diff --git a/examples/getstarted/src/api/menusection/controllers/menusection.js b/examples/getstarted/src/api/menusection/controllers/menusection.js new file mode 100644 index 0000000000..05838ac4fe --- /dev/null +++ b/examples/getstarted/src/api/menusection/controllers/menusection.js @@ -0,0 +1,5 @@ +'use strict'; + +const { createCoreController } = require('@strapi/strapi').factories; + +module.exports = createCoreController('api::menusection.menusection'); diff --git a/examples/getstarted/src/api/menusection/routes/menusection.js b/examples/getstarted/src/api/menusection/routes/menusection.js index 1ef2426ca8..be5fd1fc12 100755 --- a/examples/getstarted/src/api/menusection/routes/menusection.js +++ b/examples/getstarted/src/api/menusection/routes/menusection.js @@ -1,46 +1,5 @@ 'use strict'; -module.exports = { - routes: [ - { - method: 'GET', - path: '/menusections', - handler: 'menusection.find', - config: { - policies: [], - }, - }, - { - method: 'GET', - path: '/menusections/:id', - handler: 'menusection.findOne', - config: { - policies: [], - }, - }, - { - method: 'POST', - path: '/menusections', - handler: 'menusection.create', - config: { - policies: [], - }, - }, - { - method: 'PUT', - path: '/menusections/:id', - handler: 'menusection.update', - config: { - policies: [], - }, - }, - { - method: 'DELETE', - path: '/menusections/:id', - handler: 'menusection.delete', - config: { - policies: [], - }, - }, - ], -}; +const { createCoreRouter } = require('@strapi/strapi').factories; + +module.exports = createCoreRouter('api::menusection.menusection'); diff --git a/examples/getstarted/src/api/menusection/services/menusection.js b/examples/getstarted/src/api/menusection/services/menusection.js new file mode 100644 index 0000000000..2fb1d87752 --- /dev/null +++ b/examples/getstarted/src/api/menusection/services/menusection.js @@ -0,0 +1,5 @@ +'use strict'; + +const { createCoreService } = require('@strapi/strapi').factories; + +module.exports = createCoreService('api::menusection.menusection'); diff --git a/examples/getstarted/src/api/restaurant/controllers/restaurant.js b/examples/getstarted/src/api/restaurant/controllers/restaurant.js new file mode 100644 index 0000000000..ec87838b7a --- /dev/null +++ b/examples/getstarted/src/api/restaurant/controllers/restaurant.js @@ -0,0 +1,5 @@ +'use strict'; + +const { createCoreController } = require('@strapi/strapi').factories; + +module.exports = createCoreController('api::restaurant.restaurant'); diff --git a/examples/getstarted/src/api/restaurant/routes/restaurant.js b/examples/getstarted/src/api/restaurant/routes/restaurant.js index 027e178d9a..db1eeb2d04 100755 --- a/examples/getstarted/src/api/restaurant/routes/restaurant.js +++ b/examples/getstarted/src/api/restaurant/routes/restaurant.js @@ -1,47 +1,5 @@ 'use strict'; -module.exports = { - prefix: '/restaurants', - routes: [ - { - method: 'GET', - path: '/', - handler: 'restaurant.find', - config: { - policies: [], - }, - }, - { - method: 'GET', - path: '/:id', - handler: 'restaurant.findOne', - config: { - policies: [], - }, - }, - { - method: 'POST', - path: '/', - handler: 'restaurant.create', - config: { - policies: [], - }, - }, - { - method: 'PUT', - path: '/:id', - handler: 'restaurant.update', - config: { - policies: [], - }, - }, - { - method: 'DELETE', - path: '/:id', - handler: 'restaurant.delete', - config: { - policies: [], - }, - }, - ], -}; +const { createCoreRouter } = require('@strapi/strapi').factories; + +module.exports = createCoreRouter('api::restaurant.restaurant'); diff --git a/examples/getstarted/src/api/restaurant/services/restaurant.js b/examples/getstarted/src/api/restaurant/services/restaurant.js new file mode 100644 index 0000000000..0ed4da4757 --- /dev/null +++ b/examples/getstarted/src/api/restaurant/services/restaurant.js @@ -0,0 +1,5 @@ +'use strict'; + +const { createCoreService } = require('@strapi/strapi').factories; + +module.exports = createCoreService('api::restaurant.restaurant'); diff --git a/examples/getstarted/src/api/review/controllers/review.js b/examples/getstarted/src/api/review/controllers/review.js new file mode 100644 index 0000000000..429c8e1e94 --- /dev/null +++ b/examples/getstarted/src/api/review/controllers/review.js @@ -0,0 +1,5 @@ +'use strict'; + +const { createCoreController } = require('@strapi/strapi').factories; + +module.exports = createCoreController('api::review.review'); diff --git a/examples/getstarted/src/api/review/routes/review.js b/examples/getstarted/src/api/review/routes/review.js index fceba17148..52054d307e 100755 --- a/examples/getstarted/src/api/review/routes/review.js +++ b/examples/getstarted/src/api/review/routes/review.js @@ -1,46 +1,5 @@ 'use strict'; -module.exports = { - routes: [ - { - method: 'GET', - path: '/reviews', - handler: 'review.find', - config: { - policies: [], - }, - }, - { - method: 'GET', - path: '/reviews/:id', - handler: 'review.findOne', - config: { - policies: [], - }, - }, - { - method: 'POST', - path: '/reviews', - handler: 'review.create', - config: { - policies: [], - }, - }, - { - method: 'PUT', - path: '/reviews/:id', - handler: 'review.update', - config: { - policies: [], - }, - }, - { - method: 'DELETE', - path: '/reviews/:id', - handler: 'review.delete', - config: { - policies: [], - }, - }, - ], -}; +const { createCoreRouter } = require('@strapi/strapi').factories; + +module.exports = createCoreRouter('api::review.review'); diff --git a/examples/getstarted/src/api/review/services/review.js b/examples/getstarted/src/api/review/services/review.js new file mode 100644 index 0000000000..5422f5f938 --- /dev/null +++ b/examples/getstarted/src/api/review/services/review.js @@ -0,0 +1,5 @@ +'use strict'; + +const { createCoreService } = require('@strapi/strapi').factories; + +module.exports = createCoreService('api::review.review'); diff --git a/examples/getstarted/src/api/tag/controllers/tag.js b/examples/getstarted/src/api/tag/controllers/tag.js new file mode 100644 index 0000000000..08913dca0d --- /dev/null +++ b/examples/getstarted/src/api/tag/controllers/tag.js @@ -0,0 +1,5 @@ +'use strict'; + +const { createCoreController } = require('@strapi/strapi').factories; + +module.exports = createCoreController('api::tag.tag'); diff --git a/examples/getstarted/src/api/tag/routes/tag.js b/examples/getstarted/src/api/tag/routes/tag.js index f1bf709fdb..52be92caf9 100644 --- a/examples/getstarted/src/api/tag/routes/tag.js +++ b/examples/getstarted/src/api/tag/routes/tag.js @@ -1,46 +1,5 @@ 'use strict'; -module.exports = { - routes: [ - { - method: 'GET', - path: '/tags', - handler: 'tag.find', - config: { - policies: [], - }, - }, - { - method: 'GET', - path: '/tags/:id', - handler: 'tag.findOne', - config: { - policies: [], - }, - }, - { - method: 'POST', - path: '/tags', - handler: 'tag.create', - config: { - policies: [], - }, - }, - { - method: 'PUT', - path: '/tags/:id', - handler: 'tag.update', - config: { - policies: [], - }, - }, - { - method: 'DELETE', - path: '/tags/:id', - handler: 'tag.delete', - config: { - policies: [], - }, - }, - ], -}; +const { createCoreRouter } = require('@strapi/strapi').factories; + +module.exports = createCoreRouter('api::tag.tag'); diff --git a/examples/getstarted/src/api/tag/services/tag.js b/examples/getstarted/src/api/tag/services/tag.js new file mode 100644 index 0000000000..e9a36f01d9 --- /dev/null +++ b/examples/getstarted/src/api/tag/services/tag.js @@ -0,0 +1,5 @@ +'use strict'; + +const { createCoreService } = require('@strapi/strapi').factories; + +module.exports = createCoreService('api::tag.tag'); diff --git a/examples/getstarted/src/api/temp/controllers/temp.js b/examples/getstarted/src/api/temp/controllers/temp.js new file mode 100644 index 0000000000..52a544b43d --- /dev/null +++ b/examples/getstarted/src/api/temp/controllers/temp.js @@ -0,0 +1,5 @@ +'use strict'; + +const { createCoreController } = require('@strapi/strapi').factories; + +module.exports = createCoreController('api::temp.temp'); diff --git a/examples/getstarted/src/api/temp/routes/temp.js b/examples/getstarted/src/api/temp/routes/temp.js index ee3fc38343..6af6ec8df6 100644 --- a/examples/getstarted/src/api/temp/routes/temp.js +++ b/examples/getstarted/src/api/temp/routes/temp.js @@ -1,44 +1,5 @@ -module.exports = { - routes: [ - { - method: 'GET', - path: '/temps', - handler: 'temp.find', - config: { - policies: [], - }, - }, - { - method: 'GET', - path: '/temps/:id', - handler: 'temp.findOne', - config: { - policies: [], - }, - }, - { - method: 'POST', - path: '/temps', - handler: 'temp.create', - config: { - policies: [], - }, - }, - { - method: 'PUT', - path: '/temps/:id', - handler: 'temp.update', - config: { - policies: [], - }, - }, - { - method: 'DELETE', - path: '/temps/:id', - handler: 'temp.delete', - config: { - policies: [], - }, - }, - ], -}; +'use strict'; + +const { createCoreRouter } = require('@strapi/strapi').factories; + +module.exports = createCoreRouter('api::temp.temp'); diff --git a/examples/getstarted/src/api/temp/services/temp.js b/examples/getstarted/src/api/temp/services/temp.js new file mode 100644 index 0000000000..082866a743 --- /dev/null +++ b/examples/getstarted/src/api/temp/services/temp.js @@ -0,0 +1,5 @@ +'use strict'; + +const { createCoreService } = require('@strapi/strapi').factories; + +module.exports = createCoreService('api::temp.temp'); diff --git a/packages/core/strapi/lib/core/registries/apis.js b/packages/core/strapi/lib/core/registries/apis.js index cd4b1eccec..e3b85ae6d5 100644 --- a/packages/core/strapi/lib/core/registries/apis.js +++ b/packages/core/strapi/lib/core/registries/apis.js @@ -1,8 +1,6 @@ 'use strict'; const { has } = require('lodash/fp'); -const { createService } = require('../../core-api/service'); -const { createController } = require('../../core-api/controller'); const apisRegistry = strapi => { const apis = {}; @@ -21,22 +19,6 @@ const apisRegistry = strapi => { const api = strapi.container.get('modules').add(`api::${apiName}`, apiConfig); - for (const ctName in api.contentTypes || {}) { - const contentType = api.contentTypes[ctName]; - - const uid = `api::${apiName}.${ctName}`; - - if (!has(contentType.modelName, api.services)) { - const service = createService({ contentType }); - strapi.container.get('services').set(uid, service); - } - - if (!has(contentType.modelName, api.controllers)) { - const controller = createController({ contentType }); - strapi.container.get('controllers').set(uid, controller); - } - } - apis[apiName] = api; return apis[apiName]; diff --git a/packages/core/strapi/lib/factories.d.ts b/packages/core/strapi/lib/factories.d.ts index 488c569b15..550d44eb35 100644 --- a/packages/core/strapi/lib/factories.d.ts +++ b/packages/core/strapi/lib/factories.d.ts @@ -1,5 +1,7 @@ import { Service } from './core-api/service'; import { Controller } from './core-api/controller'; +import { Middleware } from './middlewares'; +import { Policy } from './core/registries/policies'; type ControllerConfig = Controller; @@ -7,8 +9,8 @@ type ServiceConfig = Service; type HandlerConfig = { auth: false | { scope: string[] }; - policies: string[]; - middlewares: string[]; + policies: Array; + middlewares: Array; }; type SingleTypeRouterConfig = { diff --git a/packages/core/strapi/lib/middlewares/index.d.ts b/packages/core/strapi/lib/middlewares/index.d.ts index 24f9144050..b0458239a3 100644 --- a/packages/core/strapi/lib/middlewares/index.d.ts +++ b/packages/core/strapi/lib/middlewares/index.d.ts @@ -2,3 +2,4 @@ import { Strapi } from '../'; import { Middleware } from 'koa'; export type MiddlewareFactory = (config: any, ctx: { strapi: Strapi }) => Middleware | null; +export type Middleware = Middleware;