This repository was archived by the owner on Jul 17, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Create an Addon (core)
Burnett edited this page May 14, 2016
·
5 revisions
Create a new folder inside /src/addons/ (example: MyAddon).
Please note: The given name represents your addon-name!
Create an index.coffee
file in your folder.
You can start coding now. The following template might help:
module.exports = {
namespace:
time: (router) ->
router.send(new Date().getHours())
}
The
namespace
should be lower-case and match your addons-folder-name.
Note: The namespace will be exposed to the scope of the API!
This is how an addon may look like:
module.exports = {
myaddon:
time: (router) ->
router.send(new Date().getHours())
}
Register your addon to the core-addon container inside API.coffee:
# Define Core-Addons
Addons = [
"./addons/Fs",
"./addons/Os",
"./addons/Net",
"./addons/MyAddon" # <-- This is your new addon
]
Your addon was successfully registered and you can use it:
api.myaddon.time() #=> 5
# or in a route:
#Either this way...
api.get('/myaddon/time', api.myaddon.time)
#or that way...
api.get('/myaddon/time', (router) ->
router.send(api.myaddon.time(router))
)
#or that way...
api.get('/myaddon/time', (router) ->
api.myaddon.time(router)
)
#or that way...
api.get('/myaddon/time', (router) ->
router.res.send(api.myaddon.time(router))
router.next()
)
# etc...
If you use your addon in a route (aka. as middleware), the first parameter is always the `router-object!
Addons