Cloudron makes it easy to run web apps like WordPress, Nextcloud, GitLab on your server. Find out more or install now.


Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Bookmarks
  • Search
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Brand Logo

Cloudron Forum

Apps | Demo | Docs | Install
  1. Cloudron Forum
  2. Directus
  3. Custom API endpoint

Custom API endpoint

Scheduled Pinned Locked Moved Solved Directus
15 Posts 5 Posters 2.6k Views 6 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • ruihildtR Offline
      ruihildtR Offline
      ruihildt
      wrote on last edited by
      #1

      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?

      1 Reply Last reply
      0
      • robiR Offline
        robiR Offline
        robi
        wrote on last edited by
        #2

        do you need a / at the end?

        Conscious tech

        1 Reply Last reply
        0
        • ruihildtR Offline
          ruihildtR Offline
          ruihildt
          wrote on last edited by
          #3

          Doesn't improve. 😉

          1 Reply Last reply
          0
          • robiR Offline
            robiR Offline
            robi
            wrote on last edited by
            #4

            what does the app log say?

            Conscious tech

            1 Reply Last reply
            0
            • ruihildtR Offline
              ruihildtR Offline
              ruihildt
              wrote on last edited by
              #5

              It's a standard 404, the route is not registered. It seems the file is not taken into consideration by Directus.

              1 Reply Last reply
              0
              • robiR Offline
                robiR Offline
                robi
                wrote on last edited by robi
                #6

                The entrypoint of your endpoint is the index file inside the src/ folder of your extension package.

                Try moving the index into test-endpoint/src/

                Conscious tech

                ruihildtR 1 Reply Last reply
                0
                • robiR robi

                  The entrypoint of your endpoint is the index file inside the src/ folder of your extension package.

                  Try moving the index into test-endpoint/src/

                  ruihildtR Offline
                  ruihildtR Offline
                  ruihildt
                  wrote on last edited by
                  #7

                  @robi Same result.

                  1 Reply Last reply
                  0
                  • robiR Offline
                    robiR Offline
                    robi
                    wrote on last edited by
                    #8

                    check their forum/github issues?

                    Conscious tech

                    ruihildtR 1 Reply Last reply
                    0
                    • nebulonN Offline
                      nebulonN Offline
                      nebulon
                      Staff
                      wrote on last edited by
                      #9

                      Have you tried to give it an explicit id as mentioned in the docs?

                      1 Reply Last reply
                      0
                      • ruihildtR Offline
                        ruihildtR Offline
                        ruihildt
                        wrote on last edited by
                        #10

                        Just tried, no dice.

                        1 Reply Last reply
                        0
                        • robiR robi

                          check their forum/github issues?

                          ruihildtR Offline
                          ruihildtR Offline
                          ruihildt
                          wrote on last edited by
                          #11

                          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.

                          girishG 1 Reply Last reply
                          1
                          • nebulonN nebulon marked this topic as a question on
                          • girishG Offline
                            girishG Offline
                            girish
                            Staff
                            wrote on last edited by
                            #12

                            @ruihildt This works for me:

                            • First , create index.mjs (export keyword requires module support which is signaled by mjs extension)

                            image.png

                            • 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:

                            image.png

                            /helloworld/goodbye and /helloworld/goodbye also works fine.

                            1 Reply Last reply
                            1
                            • ruihildtR ruihildt

                              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.

                              girishG Offline
                              girishG Offline
                              girish
                              Staff
                              wrote on last edited by
                              #13

                              @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.

                              1 Reply Last reply
                              2
                              • ruihildtR Offline
                                ruihildtR Offline
                                ruihildt
                                wrote on last edited by
                                #14

                                Thank you for helping me make it work.

                                Strange this .mjs thing with them, I'm going to open an issue with them.

                                1 Reply Last reply
                                0
                                • ruihildtR ruihildt has marked this topic as solved on
                                • C Offline
                                  C Offline
                                  cartpex
                                  wrote on last edited by
                                  #15

                                  I too have done exactly like this but the response is still "{"errors":[{"message":"Route /helloworld doesn't exist.","extensions":{"path":"/helloworld","code":"ROUTE_NOT_FOUND"}}]}" any idea why

                                  1 Reply Last reply
                                  0
                                  • C cartpex referenced this topic on
                                  Reply
                                  • Reply as topic
                                  Log in to reply
                                  • Oldest to Newest
                                  • Newest to Oldest
                                  • Most Votes


                                    • Login

                                    • Don't have an account? Register

                                    • Login or register to search.
                                    • First post
                                      Last post
                                    0
                                    • Categories
                                    • Recent
                                    • Tags
                                    • Popular
                                    • Bookmarks
                                    • Search