Skip to content

Instantly share code, notes, and snippets.

@nahanil
Last active February 25, 2020 21:01
Show Gist options
  • Save nahanil/ef39e3cedfba1c8e20fb50c13d5f1577 to your computer and use it in GitHub Desktop.
Save nahanil/ef39e3cedfba1c8e20fb50c13d5f1577 to your computer and use it in GitHub Desktop.
ahoyhoy
module.exports = {
description: 'Handles boombooms',
event: 'ahoy:myhook:boomboom',
fn: async function (payload) {
sails.log.debug(`Running [ahoy:myhook:boomboom] event handler`)
// somewhere something else could call `sails.emit('ahoy:myhook:boomboom', payload)`.
// This will run, payload will be passed through as the only argument.
// Probably a bad idea, who knows ¯\_(ツ)_/¯
return
}
}
/**
* Forum
*/
let Pluggable
try {
// V I haven't pulished it on NPM so this will explode for you probably
Pluggable = require('@nahanil/ahoy/lib/pluggable')
} catch (err) {
// V But I have it as a 'local' hook still for dev/hackery, so this works for me for now..
Pluggable = require('../../ahoy/lib/pluggable')
}
module.exports = new Pluggable({ // <-- does a little voodo and returns a sails compatible hook
apiBase: 'forum', // all routes below will be prefixed with this
dir: __dirname,
actions: {
// So this will get mounted like `GET /forum/index
'GET /index': { action: 'forum-index' },
'POST /category': { action: 'category/create-category' },
// ...
},
// I think everything in `./models` should get autoloaded.. If you already have a model with the same "identity" these will get ignored and it'll spit out a warning on `lift`
})
- api
- hooks
- somehook
- index.js // See other file in gist
- actions
- forum-index.js
- category
- create-category.js // "normal" actions2 file
- models
- SomeModel.js // "normal" sails-style waterline model defintion
- event-handlers
- evt-boom.js
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment