Skip to main content

后端自定义:使用 FoodAdvisor 的示例秘诀

🌐 Backend customization: An examples cookbook using FoodAdvisor

Page summary:

一本使用 FoodAdvisor 演示应用的真实后端定制示例的烹饪书,演示如何在 Strapi 中实现自定义路由、控制器、服务、策略和中间件。

🌐 A cookbook of real-world backend customization examples using the FoodAdvisor demo application, demonstrating how to implement custom routes, controllers, services, policies, and middlewares in Strapi.

🏗 About these examples

这些示例是围绕 FoodAdvisor构建的,而 FoodAdvisor不再是Strapi的特色演示应用(它已被 LaunchPad取代)。这里重要的是理解所展示的后端机制,而不是FoodAdvisor本身。这些页面将被重新访问以使用LaunchPad。

本文档的当前部分面向希望更深入了解 Strapi 后端定制可能性的开发者。

🌐 The present section of the documentation is intended for developers who would like to get a deeper understanding of the Strapi back end customization possibilities.

本节是示例的集合,演示了 Strapi 后端服务器的核心组件如何在实际项目中使用。与后端交互的前端代码也可能是某些示例的一部分,但默认情况下会以折叠块显示,因为前端代码示例并不是本手册的主要关注点。

🌐 The section is a collection of examples that demonstrate how the core components of the back-end server of Strapi can be used in a real-world project. Front-end code that interacts with the back end may also be part of some examples, but displayed in collapsed blocks by default since front-end code examples are not the main focus of this cookbook.

示例旨在扩展 FoodAdvisor的功能,这是官方的 Strapi 演示应用。FoodAdvisor 构建了一个现成的餐馆目录,由 Strapi 后端驱动(包含在 /api 文件夹中),并呈现由 Next.js 驱动的前端网站(包含在 /client 文件夹中)。

Prerequisites
  • 👀 你已经阅读了 快速入门指南 和/或理解了 Strapi 是一个 无头 CMS 它帮助你通过 内容类型构建器 创建内容结构,并通过 内容管理器 添加一些内容,然后通过 API 公开内容。
  • 👀 你已经阅读了后端自定义介绍,以便对 Strapi 中的路由、策略、中间件、控制器和服务有一个大致的了解。
  • 👷 如果你想自己测试和玩这些代码示例,请确保你已经克隆了 FoodAdvisor 仓库,设置了项目,并启动了前端和后端服务器。Strapi 管理面板应该可以从 `localhost:1337/admin` 访问,而基于 Next.js 的 FoodAdvisor 前端网站应该在 `localhost:3000` 运行。

你可以从头到尾阅读本节,或者你可能想直接跳转到特定页面以了解如何使用 Strapi 后端的给定核心元素来解决实际用例示例:

🌐 This section can be read from start to finish, or you might want to jump directly to a specific page to understand how a given core element from the Strapi back end can be used to solve a real-world use case example:

我想了解…专用页面
如何验证我的查询使用 JWT 的身份验证流程
如何以及何时使用
自定义控制器和服务
自定义控制器和服务示例
如何使用自定义策略
并发送自定义错误
自定义策略示例
如何配置和使用自定义路由自定义路由示例
如何以及何时使用
自定义全局中间件
自定义中间件示例