diap
Dependancy Injection with routing support for ExpressJs project
Last updated 7 years ago by tiengtinh .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install diap 
SYNC missed versions from official npm registry.

Diap

ependancy Injection with routing support for ExpressJs project

install diap

Example Usage

server.coffee

diap          = require('diap')

diap.setup(
	app: app
	scanFolders: [fs.realpathSync('./server/app')]
	routes: require('./routes')
	classPostfixs: [ #filename with these postfix would be Class Type (autowired with new OuserService()). Others are value type
		'_controller'
		'_service'
	]
	globalMiddlewares: 
		whenNot: 
			public: (res, req, next) ->
				console.log 'whenNot middleware'
				next()
		#when:
)

routes.coffee

routes = [	
	{
		path: '/api/user',
		method: 'GET',
		run: [ 
			'apiController.users'
		]
	}
	{
		path: '/api/test',
		method: 'GET',
		run: [ 
			'apiController.test'
		]
	}
	{
		path: '/partial/:name',
		method: 'GET',
		run: [ 
			(req, res, next) ->
				console.log 'before partial'
				next()
			(req, res) ->
				res.render('partials/' + req.params.name)
		]
		public: true
	}
	{
		path: '*',
		method: 'GET',
		run: [ 
			'serverController.layout'
		]
		public: true
	}
]

module.exports = routes

api_controller.coffee

class ApiController
	constructor: (@ouserService) ->

	users: (req, res) =>   
		@ouserService.list().then (users) ->
			res.json users

	test: (req, res) =>   		
		res.json 'test'

module.exports = ApiController

Current Tags

  • 0.0.6                                ...           latest (7 years ago)

6 Versions

  • 0.0.6                                ...           7 years ago
  • 0.0.5                                ...           7 years ago
  • 0.0.4                                ...           7 years ago
  • 0.0.3                                ...           7 years ago
  • 0.0.2                                ...           7 years ago
  • 0.0.1                                ...           7 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 1
Last Day 0
Last Week 0
Last Month 5
Dependencies (5)
Dev Dependencies (2)
Dependents (1)

Copyright 2014 - 2016 © taobao.org |