Custom API endpoint
-
Hello,
I'm trying to create and install a custom API endpoints (as documented here: https://docs.directus.io/extensions/endpoints.html)
So I compiled the example given in the Directus doc, and put it in a file named
index.js
placed in/app/data/extensions/endpoints/test-endpoint/
:var a=a=>{a.get("/",((a,e)=>e.send("Hello, Word!!")))};export{a as default};
I restarted the Directus app and tried to go to
https://example.com/test-endpoint
and nothing happens.What do I need to do to make it work?
-
I appreciate you're trying to help by asking me to do the basic checks, but the reason I ask for support here is because the whole plugin integration in Cloudron is different from the standard. (I started by checking the docs and other threads)
The closest I could find on the forum is someone struggling but then not answering @girish when asked for more details and this one where placing the files in the correct spots just worked.
-
-
@ruihildt This works for me:
- First , create
index.mjs
(export keyword requires module support which is signaled by mjs extension)
- Then , in
index.mjs
, I have:
export default { id: 'helloworld', handler: (router) => { router.get('/', (req, res) => res.send('Hello, World!')); router.get('/intro', (req, res) => res.send('Nice to meet you.')); router.get('/goodbye', (req, res) => res.send('Goodbye!')); }, };
*IMPORTANT: Note the id above. This is the REST API route path
- Then, visiting via browser works:
/helloworld/goodbye and /helloworld/goodbye also works fine.
- First , create
-
@ruihildt said in Custom API endpoint:
I appreciate you're trying to help by asking me to do the basic checks, but the reason I ask for support here is because the whole plugin integration in Cloudron is different from the standard.
AFAICT, it's very much the same as the standard. The docs are not very clear and I had to tinker a bit to make it work . For example, it talks about some src subdirectory, I am not sure what that is. It says index, but it's actually index.mjs . So, there's a bunch of errors in their docs.
-