如何使用 Directus 创建和部署端点?

How to create and deploy an endpoint with Directus?

我有一个 nooby Directus 问题:

如何创建端点并将其附加到我的项目?

我徒劳地尝试遵循文档:

创建 directus 项目

  1. npm init directus-project example-project
  1. cd example-project; npx directus start
  2. 我可以在 http://0.0.0.0:8055/admin/content
  3. 访问 directus admin
  4. CTRL+C

创建端点

  1. cd ..,离开我的 directus 项目,npm init directus-extension
  2. 端点/demo-directus-endpoint/javascript
  3. 正在 src/index
  4. 中将端点 / 修改为 /hello
  5. cd demo-directus-endpoint; npm run build

在 directus 项目中部署扩展

https://docs.directus.io/extensions/creating-extensions/

To deploy your extension, you have to move the output from the dist/ folder into your project's ./extensions/<extension-folder>/<extension-name>/ folder. <extension-folder> has to be replaced by the extension type in plural form (e.g. interfaces). <extension-name> should be replaced with the name of your extension.
  1. cd ../example-project
  2. mkdir ./extensions/endpoints/demo
  3. cp -R ../demo-directus-endpoint/dist/index.js ./extensions/endpoints/demo

index.js 看起来像这样:

"use strict";module.exports=e=>{e.get("/hello",((e,l)=>l.send("Hello, World!")))};

  1. npx directus start
17:43:40 ✨ Loaded extensions: demo
17:43:40 ⚠️  PUBLIC_URL should be a full URL
17:43:40 ⚠️  Spatialite isn't installed. Geometry type support will be limited.
17:43:40 ✨ Server started at http://0.0.0.0:8055
  1. 正在尝试获取 url http://0.0.0.0:8055/hello

curl http://0.0.0.0:8055/hello => {"errors":[{"message":"Route /hello doesn't exist.","extensions":{"code":"ROUTE_NOT_FOUND"}}]}

17:43:55 ✨ request completed GET 404 /hello 8ms

curl http://0.0.0.0:8055/hello 时如何获得 Hello, World!

感谢您的帮助

已找到答案 curl http://0.0.0.0:8055/demo/hello => 你好,世界!