首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何使用Directus创建和部署端点?

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

Stack Overflow用户
提问于 2022-05-25 15:47:24
回答 1查看 1.1K关注 0票数 3

我有一个简单的问题:

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

我试图跟踪医生是徒劳的:

创建一个直接项目

  1. npm init directus-project example-project
  • SQLite / Admin / Password
  1. cd example-project; npx directus start
  2. I可以访问http://0.0.0.0:8055/admin/content
  3. CTRL+C

的直接管理

创建端点

  1. cd ..,离开我的直接项目,npm init directus-extension
  2. endpoint /demo- directus -终结点/ javascript
  3. Modifying端点//hello in src/index
  4. cd demo-directus-endpoint; npm run build

在directus项目中部署扩展

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

代码语言:javascript
复制
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

代码语言:javascript
复制
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

试图获取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"}}]}

代码语言:javascript
复制
17:43:55 ✨ request completed GET 404 /hello 8ms

什么时候才能得到Hello, World! curl http://0.0.0.0:8055/hello呢?

谢谢你的帮助

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-05-25 15:54:21

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

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/72380698

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档