gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-05 05:40:34 40 4
gpt4 key购买 nike

我有一个 nooby Directus 问题:

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

我徒劳地尝试遵循文档:

创建一个 directus 项目

  1. npm init directus-project 示例项目
  • SQLite/管理员/密码
  1. cd 示例项目; npx 直接启动
  2. 我可以通过 http://0.0.0.0:8055/admin/content 访问 directus admin
  3. CTRL+C

创建端点

  1. cd ..,离开我的 directus 项目,npm init directus-extension
  2. 端点/demo-directus-endpoint/javascript
  3. 将src/index中的端点/修改为/hello
  4. cd demo-directus-endpoint; npm 运行构建

在 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 => 你好,世界!

关于directus - 如何使用 Directus 创建和部署端点?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72380698/

40 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com