惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

月光博客
月光博客
人人都是产品经理
人人都是产品经理
博客园 - 聂微东
WordPress大学
WordPress大学
S
SegmentFault 最新的问题
博客园 - Franky
V
V2EX
Y
Y Combinator Blog
Google DeepMind News
Google DeepMind News
J
Java Code Geeks
T
The Blog of Author Tim Ferriss
罗磊的独立博客
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
Jina AI
Jina AI
博客园 - 叶小钗
F
Fortinet All Blogs
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
A
About on SuperTechFans
M
MIT News - Artificial intelligence
云风的 BLOG
云风的 BLOG
Last Week in AI
Last Week in AI
D
Docker
博客园 - 【当耐特】
阮一峰的网络日志
阮一峰的网络日志

博客园 - egreen

在Visual Studio里用原版Copilot交互,烧DeepSeek等国模的Token,让微软和深度求索都为你打工 macOS 上通过二进制安装 Qdrant 并配置为 launchd 服务 CLI-Anything + Gear 最佳实践与踩坑修复沉淀 cli-proxy-api 工业AI报警插件 ZL.Simulator 工业级多仪器仿真与合成数据平台 SyncBus:让多台设备“齐舞”,告别协同烦恼 ZL.ParamEditor:把WinForms配置从‘苦力活’变成‘享受’! 彻底告别 WinForms SOP 开发的“老大难”! 告别“屎山”代码!Gear.NET:专为 .NET 工业自动化打造的微编排框架 electron 安装失败 【MacOS】彻底卸载Navicat dotnet项目编译运行 pnpm 安装后无法使用 macOS 彻底卸载和重装 Node.js 指南 Serena 最佳实践方案 Create Custom Endpoint in Directus CAN通讯上位机开发快问快答与最佳实践 在老项目中Claude code 中使用 ccpm功能 个人注册企业微信及机器人
directus 的endpoint功能
egreen · 2025-09-06 · via 博客园 - egreen

官方文档 (endpoints) 还是写的不够全,踩过了很多坑;

本文使用的node版本为v22.12.0; directus@11.11.0

前沿:

首先遇到的坑是,之前用低版本的node,在安装directus时有warn,但是功能是正常的。就是为了验证endpoint 时,功能验证不成功(其实是写法的问题GPT坑了我)怀疑是node版本低了。

所以升级到v23,然后再安装directus(npm install directus@11.11.0)时就彻底安装不成功了。

经过跟GPT的斗智斗勇,折腾了很久(给了我一通的解决方案),结果有个包isolated-vm需要FQ下载。

回归正题:

在项目的 ./extensions(需要跟.env中的EXTENSIONS_PATH配置保持一致 ) 文件夹下面执行指令:

npx create-directus-extension@latest

安装提示选择endpoint

Choose the extension type endpoint

✔ Choose a name for the extension endpoint-checkout

✔ Choose the language to use javascript

✔ Auto install dependencies? Yes

✔ Done

Your endpoint extension has been created at /Users/dingyuwang/3-Code/demo/muxige/extensions/endpoint-checkout

To start developing, run:

cd endpoint-checkout

npm run dev

To build for production, run:

npm run build

在extensions/endpoint-checkout 中必须要执行 npm run build;

否则,npx directus start执行时会报错。

正常的信息应该是:

npx directus start

[15:52:56.805] INFO: Extensions loaded

[15:52:56.809] INFO: Loaded extensions: endpoint-checkout, test

[15:52:56.824] WARN: "PUBLIC_URL" should be a full URL

[15:52:56.908] INFO: Server started at http://0.0.0.0:8055

可执行:curl http://localhost:8055/endpoint-checkout

返回:Hello, World!

/*

*访问路径分别是:

* http://localhost:8055/greet

* http://localhost:8055/greet/intro

* http://localhost:8055/greet/goodbye

* 千万不要画蛇添足,在url中加文件夹的名字

* id就是访问的根路径,id+router路径

*/

export default {

id: "greet",

handler: (router, countext) => {

router.get("/", (req, res) => res.send("Hello, World!"));

router.get("/intro", (req, res) => res.send("Nice to meet you."));

router.get("/goodbye", (req, res) => res.send("Goodbye!"));

},

};