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

Dim*_*urs 5 directus

我有一个新手 Directus 问题:

\n

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

\n

我尝试跟随文档但徒劳:

\n

创建一个directus项目

\n
    \n
  1. npm init directus-project example-project
  2. \n
\n
    \n
  • SQLite / 管理员 / 密码
  • \n
\n
    \n
  1. cd example-project; npx directus start
  2. \n
  3. 我可以访问 directus 管理员http://0.0.0.0:8055/admin/content
  4. \n
  5. CTRL+C
  6. \n
\n

创建端点

\n
    \n
  1. cd ..,离开我的 directus 项目,npm init directus-extension
  2. \n
  3. 端点/演示-directus-端点/javascript
  4. \n
  5. 修改端点//hellosrc/index中
  6. \n
  7. cd demo-directus-endpoint; npm run build
  8. \n
\n

在 directus 项目内部署扩展

\n

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

\n
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.\n
Run Code Online (Sandbox Code Playgroud)\n
    \n
  1. cd ../example-project
  2. \n
  3. mkdir ./extensions/endpoints/demo
  4. \n
  5. cp -R ../demo-directus-endpoint/dist/index.js ./extensions/endpoints/demo
  6. \n
\n

index.js 看起来像这样:

\n

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

\n
    \n
  1. npx directus start
  2. \n
\n
17:43:40 \xe2\x9c\xa8 Loaded extensions: demo\n17:43:40 \xe2\x9a\xa0\xef\xb8\x8f  PUBLIC_URL should be a full URL\n17:43:40 \xe2\x9a\xa0\xef\xb8\x8f  Spatialite isn\'t installed. Geometry type support will be limited.\n17:43:40 \xe2\x9c\xa8 Server started at http://0.0.0.0:8055\n
Run Code Online (Sandbox Code Playgroud)\n
    \n
  1. 尝试获取网址http://0.0.0.0:8055/hello
  2. \n
\n

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

\n
17:43:55 \xe2\x9c\xa8 request completed GET 404 /hello 8ms\n
Run Code Online (Sandbox Code Playgroud)\n

怎样做才能得到Hello, World!什么时候curl http://0.0.0.0:8055/hello

\n

感谢您的帮助

\n

Dim*_*urs 2

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

  • 谢谢迪米特里分享这些信息!不幸的是 Directus 的文档目前还不完整...... (2认同)