- Create any folder and go inside
mkdir shivam
cd shivam
- Create directus extension here
npm init directus-extension #old
npx create-directus-extension@latest #new
- Select extension-type as
endpoint
- Select name as
dog
- Select language as
javascript
- Now go to src folder on newly created extension folder
dog/src
- Edit
index.js
file
simple example
export default (router) => {
router.get("/", (req, res) => res.send("Hello World, I am Dog"));
};
// accessible on /dog
complex example
module.exports = function registerEndpoint(router, { services, exceptions }) {
router.get("/", (req, res) => {
res.send({
mesasge: "Welcome to Cat world",
});
});
router.get("/hello", (req, res) => {
res.send({
message: "Hola from Cats",
});
});
};
// accessile on /cat/ and /cat/hello
- Build extension with
npm run build
- Copy content from
dog/dist/
- Paste in
extensions/endpoints/dog
- Directus app will look like this
../extensions/endpoints/dog/index.js
- Keep extensions folder alongside
docker-compose.yml
file
---docker-compose.yml
---database
|---demo.db
---uploads
---extensions
|---endpoints
|---dog
|---index.js
- Add volume mapping for extensions
volumes:
- ./uploads:/directus/uploads
- ./database:/directus/database
- ./extensions:/directus/extensions
- Done
- Now run docker compose
sudo docker-compose up
OR
sudo docker-compose up -d