Reputation: 702
I have a nooby Directus question :
I try to follow the doc in vain :
npm init directus-project example-project
cd example-project; npx directus start
http://0.0.0.0:8055/admin/content
cd ..
, going away of my directus project, npm init directus-extension
/
to /hello
in src/indexcd demo-directus-endpoint; npm run build
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 looks like this :
"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
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
What to do in order to get Hello, World!
when curl http://0.0.0.0:8055/hello
?
Thank you for your help
Upvotes: 5
Views: 5526
Reputation: 81
Be careful, there might be an issue with the /dist
in the extension.
I advise you to move the index.js
that is in the /dist
and place it at the root of the extension folder.
Then, in the package.json
, you will need to modify the path by removing the dist/index.js
.
"directus:extension": {
"type": "endpoint",
"path": "index.js",
"source": "src/index.ts",
"host": "^10.3.4"
},
This should resolve the issue for some people, especially if you are using Docker for Directus.
Upvotes: 0
Reputation: 702
Answer found curl http://0.0.0.0:8055/demo/hello => Hello, World!
Upvotes: 3