-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdriver.js
48 lines (39 loc) · 1.46 KB
/
driver.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
const Api = require('claudia-api-builder')
const api = new Api()
/**
* Blockbase Claudia JS driver (app.drivers.claudia)
* @namespace app.drivers.claudia
* @memberof app.drivers
* @author Alexandre Pereira <[email protected]>
* @param {Object} app - Application namespace
*
* @returns {Object} driver object containing the api object
*/
module.exports = (app) => {
if (!app.config.has('claudia'))
return app.drivers.logger.error('Claudia', 'Cannot init the driver, missing config')
const config = app.config.get('claudia')
/**
* Initialize the routes
* @memberof app.drivers.claudia
* @todo add the express builder for twig
*/
function route() {
for (let route of config.routes) {
if (route.type === 'view')
api[route.method](route.src, () => {
// todo : return twig built
return `should render : ${app.root}/views/${route.dest}.twig`
}, route.extra)
if (route.type === 'controller') {
let path = route.dest.split('::')[0],
method = route.dest.split('::')[1]
let controller = require(`${app.root}/controllers/${path.replace('.', '/')}`)(app, api)
api[route.method](route.src, controller[method], route.extra)
}
}
}
// auto-routing at launch from claudia.routes in config/{env}.yml and listen
route()
return {api}
}