directus

How to create and deploy an endpoint with Directus?


I have a nooby Directus question :

How to create an endpoint and attach it to my project ?

I try to follow the doc in vain :

Create a directus project

  1. npm init directus-project example-project
  1. cd example-project; npx directus start
  2. I can access directus admin at http://0.0.0.0:8055/admin/content
  3. CTRL+C

Create an endpoint

  1. cd .., going away of my directus project, npm init directus-extension
  2. endpoint / demo-directus-endpoint / javascript
  3. Modifying endpoint / to /hello in src/index
  4. cd demo-directus-endpoint; npm run build

Deploy extensions inside directus project

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 looks like this :

"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. Trying to get 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

What to do in order to get Hello, World! when curl http://0.0.0.0:8055/hello ?

Thank you for your help


Solution

  • Answer found curl http://0.0.0.0:8055/demo/hello => Hello, World!