如何使用 Directus 创建和部署端点?
How to create and deploy an endpoint with Directus?
我有一个 nooby Directus 问题:
如何创建端点并将其附加到我的项目?
我徒劳地尝试遵循文档:
创建 directus 项目
npm init directus-project example-project
- SQLite/管理员/密码
cd example-project; npx directus start
- 我可以在
http://0.0.0.0:8055/admin/content
访问 directus admin
- CTRL+C
创建端点
cd ..
,离开我的 directus 项目,npm init directus-extension
- 端点/demo-directus-endpoint/javascript
- 正在 src/index
中将端点 /
修改为 /hello
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.
cd ../example-project
mkdir ./extensions/endpoints/demo
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!")))};
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
- 正在尝试获取 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 => 你好,世界!
我有一个 nooby Directus 问题:
如何创建端点并将其附加到我的项目?
我徒劳地尝试遵循文档:
创建 directus 项目
npm init directus-project example-project
- SQLite/管理员/密码
cd example-project; npx directus start
- 我可以在
http://0.0.0.0:8055/admin/content
访问 directus admin
- CTRL+C
创建端点
cd ..
,离开我的 directus 项目,npm init directus-extension
- 端点/demo-directus-endpoint/javascript
- 正在 src/index 中将端点
cd demo-directus-endpoint; npm run build
/
修改为 /hello
在 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.
cd ../example-project
mkdir ./extensions/endpoints/demo
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!")))};
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
- 正在尝试获取 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 => 你好,世界!