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
  • SQLite / Admin / Password
  1. cd example-project; npx directus start
  2. I can access directus admin at
  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

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

curl => {"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 ?

Thank you for your help

1 Answer

Answer found curl => Hello, World!

2

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

You Might Also Like